我正在努力让我的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
正在打印.