【发布时间】:2015-05-20 14:50:20
【问题描述】:
我正在尝试让我的 Passport 本地策略发挥作用。
我已经设置了这个中间件:
passport.use(new LocalStrategy(function(username, password, done) {
//return done(null, user);
if (username=='ben' && password=='benny'){
console.log("Password correct");
return done(null, true);
}
else
return done(null, false, {message: "Incorrect Login"});
}));
然后在这里
app.use('/admin', adminIsLoggedIn, admin);
function adminIsLoggedIn(req, res, next) {
// if user is authenticated in the session, carry on
if (req.isAuthenticated())
return next();
// if they aren't redirect them to the home page
res.redirect('/');
}
它总是失败并重定向到主页。
我不明白为什么会这样?为什么不认证?
在我的控制台中,我可以看到 Password Correct 正在打印。
为什么它不起作用?
【问题讨论】:
标签: node.js express passport.js passport-local