From the course: Advanced Express

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Providing a logout link

Providing a logout link

From the course: Advanced Express

Start my 1-month free trial

Providing a logout link

- [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…

Contents