- [Instructor] It's a good practice to also provide
a way for users to logout and the sample project
already contains a link for it here
under the user name and logout.
We see that the route/user/logout does not exist yet.
We will implement it now.
For that I'm heading back to visual studio code
and in there I open server, routes, users, index js
and right after the the route for the log in
I will now add a new route, router.get/logout,
request, response as always.
And password automatically adds a function logout
to the request object.
All we have to do it call it and it will log the user out.
Behind the scenes it will clear the login session.
So I will now call request, logout
and next I want to redirect the user to the index page
because maybe the user was on some privilege page
and after logout they should of course end up somewhere
that is accessible for all users.
Let's restart our application and let's click on logout now,
and we see that the user got logged out
so we are back at the navigation containing account
and the login page.
So we can now authenticate users,
but what do they gain by logging in anyways.
There should be routes that are only available
for privilege users like my account.
In the next videos I will show you
how to protect route with password, it's quite easy.