Categories
JavaScript Answers

How to fix Passport.js in Node not removing session on logout?

Spread the love

To fix Passport.js in Node not removing session on logout, we call the session.destroy method.

For instance, we write

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

to call req.session.destroy to destroy the session.

We call it with a callback that’s called when the session is destroyed.

And we call redirect in the callback to redirect to /.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *