All right.
So we can log in at least using Postman for now.
Our back end log in, and we need a way to log out.
And what log out means in this case is getting rid of the JWT cookie.
All right.
So what we're going to do is go to our user controller and we already have a log out user function.
We already have it hooked to a route.
So we just need to change what we have in here.
And we're basically going to take our cookie.
So res dot cookie, I don't know if that's exactly what I want, so I'm just going to type it out.
So dot cookie and to clear this, we just want to set it to an empty string and we want to set it to
expire.
Now the cookie name is what we're going to put in here first, which is JWT, right?
And then we're going to set the value to nothing.
And then we'll pass in an object with some options.
So we'll set Http only to.
True.
We're going to set expires.
All right.
So expires is now going to be set to, we'll say, new date and just pass in zero.
So we want this to expire.
So this is how we can just clear the cookie and then we want to respond.
So we'll say res dot and let's say status.
We'll respond with a 200 status and we'll say dot Jason and let's say just send a message.
So message will say logged out.
Successfully.
All right.
So that should do it.
So we can test it out.
Let's go over to Postman.
And right now I'm logged in so you can see I have this one next to cookies.
Right.
And if you click on cookies, you can see JWT.
Before we were just deleting the cookie manually to log out, but now let's go to the log out route.
And let's go ahead and send and we get logged out successfully.
And notice that the if I go to cookies, it's not there anymore.
If I click on the cookies right here, it's not there either.
So let's try it one more time.
We'll log in.
Let's log in as John.
Okay, so now we're logged in.
Let's log out.
And let's try actually, before we log out, let's try to access a protected root, like get user profile.
So that works.
Then we'll go to log out.
Click send log out successfully.
Let's go back to get user profile and send.
And now we're not authorized.
Okay?
So we can now authenticate and we can log out.
So the next thing we need to do is we need the ability to register, okay?
Because right now we don't have any register functionality and I want to make it so when we register,
once we go through that process, then the cookie gets set.
So basically we, we directly log in right, right after we register.
So we're going to do that in the next video.