Welcome back.
In this video, let's see how we can implement login out.
And it's very simple with experts.
So back to our code.
Let me collapse the terminal here and let's remove this.
Once the next step is let's implement the logout functionality, we can bring it any way we want.
So let's bring it here as log out and here is the handler app dot get and slash look out.
Log out and then as always, our callback function, req and response and there you go.
So how are we going to look out?
We can look out on the rec dot session.
We have a method called destroy.
So let's try out first and see.
Let's come down here and then let's redirect the user to the log in page after logging out.
So let's see how we are going to achieve this one.
Well, so back to the template of the profile.
That's where we have the log out.
So let's look in as lazy.
One, two, three, four, five and log in.
And now on this button, when I click on that, I want to delete the session and I believe we have that
one already where we implemented the cookie based functionality.
I think, yeah, it's here.
So this one is for the cookie based one.
So let me comment one.
And now let's take to the session one, which is this functionality.
So now let's go ahead and then click on that.
So let's refresh it now because I've refreshed my server.
That's why I got that.
So let's log in again.
And let's look out and you can see that everything is working.
Now, if I go to protected and you can see that the unauthorized template has been rendered, meaning
that I have locked out.
So this is how we can lock out a user that is our sun.
So again, as soon as I refresh the server, you can see that the session destroyed.
Do you remember?
Yes.
So let me prove to you one more time, then we get back into how we are going to avoid that.
So here let's console.log the rec dot session and I believe for this one we have done it before.
So if I open the terminal and now if I go to home page and let's go to homepage and refresh now and
check it out.
You can see that on this session there is no log in user, but as soon as I log in with this user.
You can see that.
And then you go to homepage and now you see that I have the user as soon as I restart the server.
Yes, let's go and I go to homepage.
Let's refresh it.
And now we see that there is no log in user.
This is a reason why we say that HTTP servers are stateless, so it is our responsibility to keep the
search engine in a state.
And then this video we are going to implement how we can save the session inside MongoDB.
So any time we want to visit, whether our server shut down or we look out, we still have the user
inside our database.
So let's get into that in the next video.