Okay.
And lastly, let's set up the logout route.
And first, let me just showcase why we need one.
And then step by step.
We'll set up everything on a server as well as the front end.
So at the moment I'm on a dashboard.
Everything is dandy.
I can navigate to all my pages.
And I can clearly see that I still have a cookie with my token, of course.
And if I go to a logout, what happens?
I'm going to be kicked back to the landing page.
Correct?
Yep.
That is awesome.
But I can still see the token over here.
Basically, I can still see the cookie.
And what that means is that once I let's say, refresh, I'm going to go back to the application.
Why?
Well, because we perform a request.
We get the current user cookie is valid, so we get the info about the user and all that, and that
is probably not the best approach.
Essentially what we want to do is to set up a root.
That we can call when we log out.
So not only we set up the features on the front end, not only we set, let's say everything back to
the default on the front end, but we also want to remove that cookie.
We want to remove it.
And as a result, the user is not going to go automatically back to the dashboard.
So here's what we want to do.
Let's bring our gate to the redmi.
So.
As far as the log en route, we want to go with a controller.
We'll go with the red dot cookie.
We need to set the same name.
So in our case, that is token.
We need to provide some kind of value.
So in my case, I'm just going to go log out.
But this can be literally anything.
And the gotcha here is following that we want to go with expires and then we just need to decide and
how long this is going to expire.
So just to showcase that, it's going to come back and then disappear, I'm going to go with one second.
But essentially you can do something like this where the cookie expires automatically and the result
is going to be that the user wants he or she logs out, actually.
Is not going to have that cookie in the browser.
As far as the response, it doesn't really, again, matter.
If you want to display something, you can provide a message, but as long as you send the 200, you're
going to be good to go.
Let's keep looking.
We want to, of course, set it up in a root like so.
And then as far as the frontend, when we log out the user, we simply want to go with a wait and then
auth logout.
That's it.
That's all we have to do because again, we're not going to make any changes on the front end, we're
just going to remove that cookie.
And in order to remove the cookie, we need to go with the same cookie, the name here, so token and
then provide some kind of string value over here.
In my case, that is going to be logout.
And then yes, it's still a HTTP only.
Now it doesn't have to be the secure one.
Again, we're just removing that cookie from the browser.
And then as far as the expires, just so I can showcase that it actually comes back and then goes away.
I'm going to go with one second, but.
Essentially we can just go with data now.
So let's start working on that.
We want to go to the controllers.
So I have here controllers of controllers get current user.
Okay.
That's good.
Let's go with console.
Log out.
And that is going to be a sync rec and Russ.
And let's go with the resident cookie, and then we want to provide the token value.
By the way, this is not.
Correct spelling.
This should be like this.
So token, I'll say log out.
And then we want to provide those options there.
So http only.
Yep, that's going to be the case.
So HTTP only.
True.
And then as far as the expiration, I'm not going to repeat what I just said, like I believe three
times expires and that is equal to new date.
Now let's pass in a date that now.
And in my case, I'm going to add that one second just so we can see basically the cookie coming back
and then expiring.
And after that, we want to go with that red dot status.
So let's set up here as that status.
And that is equal to status codes we're going to go with.
Okay.
And then let's set up the JSON here and let's say that JSON and will provide a message.
So it's a message and user.
Logged and out.
Okay, good.
Now let's navigate to the root.
And we obviously want to get that.
So in the throughout the first and let me double check, I don't think I added.
Okay, my bad.
So we need to export that.
Of course.
My apologies.
So, comma, log out.
Good.
And then let's go to Arthur out.
You want to grab that?
Log out.
And then let's set up I mean, in my case, I'm going to do right after login, but you don't have to
so really matter.
And you know what?
In order to speed this up, I'm just going to copy and paste.
So we're looking for the log out here.
So that's the URL.
It's going to be a get root.
And we don't want the limiter doesn't really matter.
I just go with the log out here.
Let's save that.
And like I said, on the front end, we simply want to call this a root when we log out.
So let me find my app context.
Let me find the log of user.
It's a right over here.
And then on top of it, let's just go with a wait.
Wait.
Auth fetch and then we're going to go with get root and we'll go with slash auth forward slash logout.
And now it's the Stroud.
So let me go back to my application.
Let me refresh just to stay on the safe side.
Yep.
So users here, I.
Navigate back to the dashboard.
Everything's fine.
And now let me log out and not notice.
So essentially, we see this cookie over here.
But let's say if I go and click on it one more time, we can see that there is no cookie anymore.
And again, that is just the showcase that it does expire.
So now let me go back to the auth controller and essentially we want to set it equal to the dot now.
Effectively, it expires right away.
So now let me test it out here.
I'm going to go to John.
My favorite user, of course.
Let me log in.
And of course, it complains that credentials are not correct.
So let's try one more time.
We're good.
So that's my cookie.
And then once we log out, everything should work.
Notice we have no cookie anymore and we're directed back to the landing page.
And that actually concludes the cookie setup.
Like I said, there was quite a bit of refactoring.
Unfortunately, there's no other way.
But now you know how we can set up auth both ways with local storage or by.
Just communicating back to the server.
So each and every time we need some user info, we have a specific route that gets us everything, and
all of the token info is stored in the cookie, which is only accessed by the browser.
And essentially that is more secure.
And also.
It's less work on the front end.
The reason why we had to do so much refactoring is because we already had the local storage approach.