Categories
JavaScript Answers

How to fix PassportJS in Node not removing session on logout with JavaScript?

Spread the love

Sometimes, we want to fix PassportJS in Node not removing session on logout with JavaScript.

In this article, we’ll look at how to fix PassportJS in Node not removing session on logout with JavaScript.

How to fix PassportJS in Node not removing session on logout with JavaScript?

To fix PassportJS in Node not removing session on logout with JavaScript, we can use the req.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.

The callback is run when the session is destroyed.

Conclusion

To fix PassportJS in Node not removing session on logout with JavaScript, we can use the req.session.destroy method.

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 *