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.