In this video.
Let's see how we can implement logging out a user.
So let's look at the process.
Logging out a user simply means that we are going to remove the user from the cookie, and that is all.
So if I log in as Lily here, that is Lizzie.
And the password is this one.
When I hit send, you can see that I have the profile page and if I check the cookies, you will see
that I have the details about the user.
So the whole logic is that when I click on the log out, I won't remove the details from the cookies
and that's what we are going to do.
So how can we get that one done?
It's pretty simple with EXPRESS.
So I'm going to create a route where we are going to click on this button to initiate that route.
So here before or after, log in, let's do it after log in.
Here is going to be the log out and let's create the route app dot get and here are going to be the
log out and and the arrow function.
And here what we are going to do is we need to delete the cookies.
So how are we going to do it?
Well, it's pretty simple with express.
So on the response, we have a method called Cookie.
And for this one we pass in the property that you want to remove.
In one case we want to remove the username, or if we want to remove everything, we are going to pass
in full name, user name and name.
So here we go.
All right, so we pass in full name here.
I want to remove name and copy this one and I also want to remove the username.
And lastly, I also want to remove the name.
I think this name is not from us from database, I think it is from this one and the one that we set.
So don't worry about the name.
So let's remove the name by right.
Click in and click on that.
So back here now let's go to the log out before the cookie will be set unless we return something from
the root.
So here address, dot redirect and after deleting, let's go to the log in page.
I'll start.
So moment of truth.
So when I click on Look Out, you can see that I have removed the cookies and again I can log in again
with Lizzy and one, two, three, four, five and hit send.
Now I have the name here but I see undefined for the username.
What is the problem?
Maybe for logging in.
I am not sending or pass in the right details.
Oh sorry.
Supposed to be user found but not user found name.
Yes.
So again, let's look out now.
I have removed that.
So let's log in back again.
And hit send log in and now we have the log in again as quantified well.
Oh sorry user found dot full name the user name.
Sorry guys.
Bottom side.
All right.
So again, let's look out and then let's log in again, Lizzie and one, two, three, four, five and
hit log in.
And now we have the right details.
So if I go to protected.
Yes.
Where I come by, as soon as I go to the profile, there is no key or maybe button to go there unless
I log in again before I can go to my profile like that.
And as that when I click look out, I remove that.
If I go to protect it, you are not log in now everything is correct.
So in the next video, let's talk about session based authentication, meaning we are going to improve
the way we implemented cookie based authentication.