【发布时间】:2016-04-25 19:48:45
【问题描述】:
我使用的是 express 4、passport 和 express-flash。当我使用罐装护照中间件功能并设置 failureFlash: true 时,一切正常。但是,当我在同一个路由文件中的注册函数中使用自定义回调时,它不起作用。 messages.info 对象为空。
这很好用:
router.post('/login', passport.authenticate('local-login', {
successRedirect: '/dashboard',
failureRedirect: '/login',
failureFlash: true
}),
function(req, res){
}
);
这导致我的 messages.info 对象为空:
router.post('/register', function(req, res, next){
passport.authenticate('local-signup', function(err, user, info){
if(err){
req.flash('info', err);
res.render('register');
}else{
res.render('profile');
}
})(req, res, next);
});
我使用玉作为我的预处理器:
if (messages.info)
.message.info
span= messages.info
没用!
【问题讨论】:
-
你用过
app.use(flash());吗? -
尝试插入flash作为认证选项,即passport.authenticate('local-signup', { failureFlash: true }, function(err, user, info){...})
-
我确实使用过 app.use(flash());在我的 app.js 文件中。当我将 {failureFlash: true} 放在我的本地注册函数中时,它会抛出 500。我不确定为什么内联中间件调用与自定义回调选项不同... F@$ck!