Now, let’s take a look at how to log users out. Passport.js exposes a logout function within the request object: req.logout. The function can be called from any route handler in order to terminate a login session. It essentially removes the req.user property and clears the login session (if any).

app.get("/logout", (req, res) => { req.logout(); res.redirect("/"); });

By terminating the session, the user will have to re-authenticate in order to create a new session.



A "/logout" request has been provided.

Add the missing code to log out a user and redirect them back to the login path, "/login".

Type node app.js into the Terminal to start the node app.

Press the Check Work button to check your work for each checkpoint.


If you haven’t already, in the terminal run the command:

node app.js

Press the circular arrow button in the mini-browser to load the webpage. An image showing a cursor pressing the refresh button to refresh the iframe which contains a mini-browser.

Within the mini-browser attempt to log in with the following credentials:

Once logged in, click on the logout button to ensure that you can log out successfully.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?