why am i getting this error when i try to req.logout()?

Issue

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("/")
})

Solution

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("/");
  });
});

Answered By – Passionate Coder

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published