Passportjs-req.logout函数不存在 [英] Passportjs - req.logout function does not exist

查看:46
本文介绍了Passportjs-req.logout函数不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条看起来像这样的路线:

I have a route that looks like so:

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

错误:对象#ServerResponse没有方法注销"

Error: Object #ServerResponse has no method 'logout'

调用此路由时,Request对象不包含注销功能.我认为这是因为我的中间件顺序错误.那是对的吗?这是我的配置:

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');

这些护照中间件警告是否在任何地方都有记录?项目README提供了一个示例,并且按顺序包含了这些中间件,但是我怀疑另一种中间件集或使用会破坏我的利益.谁能为我阐明一下?

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?

推荐答案

您不小心切换了 res req 形式参数.应该是:

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

exports.logout = function(req, res){
  req.logout();
  res.redirect('/');
}

这篇关于Passportjs-req.logout函数不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆