Beautiful, and our initial setup is going to look something like this where effectively we want to
set up another middle where.
So the end result is going to be that for certain routes before we can access throughout, as an example
of that user, there's going to be a middleware that checks for that token.
So if the token is not power or it's not present, then we'll send back the error.
And like I said, we will log out the user on a frontend as well.
Now what do we want to do?
Well, we want to create off jurors or authenticate jurors in middleware.
Marcus, I'm going to go with off because authenticate is another dewji that I have trouble spelling
and writing.
And then inside of the off drafts, I want to create a function.
I'll call it off.
I'm going to go with async.
Remember, we're still accessing Rackauckas and next, and this is very important.
So we're passing it on to a next middleware, which in our case is of the controller.
And for timing, we just want to console.log.
We want to console.log whether everything works, we want to export as default.
And now in this case, I will call this authenticate user because it just makes a little bit more sense
to me.
And essentially, we want to import that in the author out and we'll stick it in front of the update
user.
So please keep in mind logged in the register are still public roads, but this is going to be a private
route.
Where we will check for that user and then when it comes to jobs, like I just said, all of the routes
will be restricted and essentially we have two options either you can do that in server gas.
So we import authenticate user and then just place it in front of the jobs router.
So that means that each and every request about goes to ports, large jobs.
We'll have that authentication or you can go to jobs zones and then do that manually.
So in this case, I'm just showcasing one.
The show starts one.
But keep in mind, you need to add that to each and every route.
Now, in this case, I think I'm going to go with this option where essentially I'll stick the authenticate
user in front of jobs.
But to tell you, honestly, it is actually my preference to do that in the world.
Since that way, I can clearly see which routes have that restricted access.
And keep in mind that if you're going to have a setup where authenticate user.
Is not applied to all the.
Well, then you don't have two options and you literally have only one option where we have to go to
the house, one import the main law and then choose their out you want to authenticate.
Hopefully that is clear.
So now let's get cracking.
And first we want to go to Manila folder.
I don't think I said I'm going to go with off an address now instead of the office.
Yes.
What do we want to do?
Well, we want to set up that function, correct accounts.
It's going to be equal to an all online.
It's going to be a cinch.
And we're looking for rec and rice and a next round inside of the function body.
Let's go with console.log and then authenticate and user and then let's remember to go with next webwise.
The user will be hearing we want to go with export and then default to export default, and then I'm
looking for off.
And let's start, I guess, with a crossroads.
So I'm going to navigate over here.
I want to import that from where, well, I'm going to be looking for the off middleware, correct?
So let's just go here and let's say that the name will be authenticate user and ticket and then user.
And once we have that one in place, then we'll go with from and now we're looking for the middleware.
And then more specifically off, hopefully this one is spelt correctly.
I mean, I don't see the Blue Squiggly Line, so what's my right?
And then like I said, these two are still public.
I mean, anyone should have ability to register and log it correct.
However, once we want to update the user, this is going to be restricted to authenticate user like
so.
So let's go here and then let's say authenticate and then user, let's save this and I'll do the same
thing in the jobs one.
So copy of this one?
I mean, there's no point to retype the import one more time.
And or you're not sorry, I'm not going to go this route.
I'm not going to add to each and every one of them.
My apologies.
Actually, I want to remove it, and let's navigate to the server now since the middleware is in the
same path.
Well, let's do this.
So I'm going to go with authenticate user, but we're not going to levels up.
Remember, now we are in the server, so the path is a little bit different than let's keep on scrolling
and where we have this one over here, let's just go with authenticate and user.
So that is the name I'm going to go with comma.
And once we have everything in place, I think there's something missing.
The fact is that I don't have Jess.
My apologies.
So let me go back to the answers as well.
Otherwise, we know that we're going to get about Dewji, where essentially we need to add that extension.
I've got a double check up.
There was actually errors, and now everything works.
So now just go to a postman and test it out, where if I go with update user or any of the jobs ones
I should see in a console that I should see authenticate user.
So let's try it out and navigate to the postman have log in.
And I just thought, OK, that's awesome.
But I want to go with update user now.
I think, I mean, I'm not going to pass anything and we're just going to send it, and I have the update
user string.
So that's cool.
But what I'm really looking for is a vest for I can see a string that means that now every request that
goes to a user, it's going through this middleware.
Correct, and the same deal is going to be over here in jobs.
Now, I'm not going to do with all of the jobs, but I'm just going to get one and the same deal that
I have authenticate user and notice the request.
And this is going to be our initial user authentication setup.