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 /.