So we need to keep working on this authenticate token function in handler's dash API.
And what we'll do right now is get the authorization header and strip out the part that we need, which
is the actual token.
So what we'll do is we'll leave the where you will be getting rid of that before too long.
But for right now, let's get the authorization header.
And that's nothing more than getting the header.
So our header don't yet and we're going to get authorization
or is it at violin and make sure you spell that right or none of this will work.
So first thing will do is check to see if that actually exists.
So if authorization header is equal to an empty string and we don't have it, so it will return.
No, we don't want to return it because we don't have one.
And a new error.
Errors start new and we'll return no auth or ization header received, OK?
So now if we get past that, then we actually have an authorization, so let's break it up into its
parts that are parts he's assigned the value of from the strings package.
We're going to split.
The authorization letter and we'll split it on a on a one space, which occurs between Barer and the
token itself.
So back in base layout, when we send that, we're sending the authorization header named authorization,
and it consists of the word barer followed by a space.
So we're splitting it on the space.
So we need to check something.
We need to check if the line of.
Heter perts is not equal to two or.
Tetrapods zero is not equal exactly to barer, then again, and I have a typo here, they should close
here and we don't need this one here.
That's better.
Then again, we'll return nil and error start new and this time will say.
No authorization letter received.
Same thing now, just so you know, even though I'm generating these error messages right here, I'm
actually not going to use them.
I like to give as little information as possible to users who are trying to authenticate when something
goes wrong.
I don't want to give any indication as to what is missing, but I put these error messages in here and
I'll make different ones as time goes on, because some people actually like to have more meaningful
messages sent to the end users.
But in my case, when it comes to authentication, I'm going to tell them the bare minimum.
But it's up to you.
So now we'll get the token token is equal to or assign the value of
header parts index one, because that's where the tokens should be.
Now, we'll do another check if the length of token, which is a string, is not equal to twenty six.
And in our case it will always be twenty six.
So if it's not equal to twenty six then we'll just return null and error or start new and we'll say
authentication token wrong size.
Now if we get past all of this now we will in the next lecture get the user from the tokens table.
OK, so what we've done so far is to actually grab the necessary header authorization, make sure that
it exists.
Then we make sure that the content of the authorization header consists of the word barer, followed
by a space followed by some string that is exactly twenty six characters long.
And if we get past all of that, then we can try to get the user from the tokens table from the database
and we'll take care of that in the next lecture.