Error which i am getting:
Error: req#logout requires a callback function
My code:
// @desc Logout User
// @rote GET /auth/logout
router.get("/logout", (req, res)=>{
req.logout()
res.redirect("/")
})
CodePudding user response:
req.logout() is an asynchronous function (it was not this way before, they only introduced this change recently for security reasons), and your current code is synchronous, which is why you get this error.
You can fix this error by modofying your code as follows:
app.post('/logout', function(req, res, next) {
req.logout(function(err) {
if (err) { return next(err); }
res.redirect('/');
});
});
CodePudding user response:
This is a change introduced in recent release. You can find it here in detail https://medium.com/passportjs/fixing-session-fixation-b2b68619c51d
From the documentation https://www.passportjs.org/concepts/authentication/logout/
try below code
router.get("/logout", function(req, res, next) {
req.logout(function(err) {
if (err) {
return next(err);
}
res.redirect("/");
});
});