0

I have a route that looks like so:

  exports.logout = function(res, req){
      req.logout() // I blow up
      res.redirect('/')
    }

Error: Object #ServerResponse has no method 'logout'

The Request object does not contain a logout function when this route is called. I assume that this is because I have my middleware in the wrong order. Is that correct? This is what my configuration looks like:

app.use(express.methodOverride());
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.cookieParser('meow'));
app.use(express.bodyParser());
app.use(express.session());
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(express.logger('dev'));
app.use(require('less-middleware')({ src: __dirname + '/public' }));
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');

Are these passport middleware caveats documented anywhere? The project README gives an example and I have those middleware included in that order but I suspect that another middleware set or use is breaking me. Can anyone shed some light on this for me?

rgettman
  • 176,041
  • 30
  • 275
  • 357
Nick
  • 19,198
  • 51
  • 185
  • 312

2 Answers2

3

You accidentally switched your res and req formal parameters. Should be:

exports.logout = function(req, res){
  req.logout();
  res.redirect('/');
}
go-oleg
  • 19,272
  • 3
  • 43
  • 44
0

Looks like you switched req and res.

Error: Object #ServerResponse has no method 'logout'

ServerResponse is res not req.

user568109
  • 47,225
  • 17
  • 99
  • 123