我正在尝试让我的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('/');
}
这个网站总是失败并重定向到主页。
我想不出为什么会发生这种情况?为什么它无法进行身份验证?
在我的控制台中,我可以看到“密码正确
”正在打印。为什么它不能工作?