0

I'm receiving error Error: req#logout requires a callback function when trying to log out of my app.

The issue is due to a passport.js update (from 0.5.3 to 0.6.0) which removed a vulnerability and there are several documented fixes on stack but even after adding a callback to my logout function (in app.js below), I'm still receiving an error response.

  • Error! Your request cannot be completed. Please validate your information and resubmit.`

I recently removed high-risk vulnerabilities which is what I'm thinking created this issue because logout was working a few weeks ago.

app.js

const passport = require('passport');

app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(User.authenticate()));

passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());

app.use((req, res, next) => {
    res.locals.currentUser = req.user;
    res.locals.success = req.flash('success');
    res.locals.error = req.flash('error');
    next();
})

app.get('/login', (req, res) => {
    res.render('users/login');
})

app.post('/logout', function(req, res, next) {
  req.logout(function(err) {
    if (err) { return next(err); }
    res.redirect('/');
  });
});

client side code

<a class="dropdown-item fs-5" href="/logout">Logout</a>

I've tried console logging the error within the error handler but I can't get any additional detail as to what's happening. How do I fix my logout?

econobro
  • 315
  • 3
  • 17

0 Answers0