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
- [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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Understanding cookies and sessions3m 54s
-
(Locked)
Adding cookies and sessions to Express5m
-
(Locked)
Inspecting the session object2m 18s
-
Introduction to Passport1m 39s
-
(Locked)
Adding Passport to Express3m 55s
-
(Locked)
Setting up an authentication strategy for Passport5m 18s
-
(Locked)
Serializing and deserializing users3m 25s
-
(Locked)
Creating a login form with Passport5m 14s
-
(Locked)
Providing a logout link2m 1s
-
(Locked)
Authentication vs. authorization1m 23s
-
(Locked)
Protecting routes3m 35s
-
-
-
-