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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.