Beautiful.
And once we have set up our postman.
Now, let's continue and work on the authentication.
So essentially, yes, we can log nicely the authorization horror, but what's next?
Well, it's kind of similar to whatever we already have in the controller, where if a value is missing
or maybe the password doesn't match, we do what we throw error.
Now, in this case, we already have on authenticated error.
Remember, we used that one in the log in one, so we can definitely import that.
Just remember that we're looking for index.
This is somewhat of a big gotcha when you're using the modules in code, and I'm talking about the six
modules.
And then let's start very slowly.
So just baby steps where, yes, I have the header and I'll just check if the header is present, then
beautiful, pass it on to the next middleware, in our case, the controller.
However, if it's not present.
Then we go with an authenticator.
So this is the case where the error is not 400 or 404, so not phone.
Actually, it is for.
And if you remember that was on authorized.
And as far as the message, I'm just going to go with authentication invalid.
So let's get cracking.
When I get off, Jess, I'm going to look for unauthenticated error.
Yep, this is going to be the default setup.
But remember, we need to go with Index Jess, and let's just set up a simple condition where I'm going
to say if there is no authorization hotter than throw the error.
So if no off error than let's go with throw new and then we're looking for an authenticated error.
And let's just go with authentication.
And invalid.
So let's try this out right now as far as the postman, so I'm going to navigate back and I'm going
to go update user now at the moment to have better talking and I have token set up.
Now, if we want to double check that one, just log in one more time here.
Everything is correct and not if we go update user, we should see the string.
All of that is nice.
Now if I go here where I have the authorization and if I'm just going to go to north, check it out.
Now what?
I you getting back for her one and then authentication.
Again, this is the most basic setup in next video make way more complex functionality, but the general
idea is going to be exactly the same where if the token is not provided, we send back for one, if
everything is in place, then we pass it on to the next middle or in our case, the controller for the
route that the user is trying to access.