护照的req.isAuthenticated总是返回假的,甚至当我做硬编码(空,真)
我试图让我的护照地方战略的工作。
我有这个中间件设置:
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
正在打印。为什么不工作?
我有一个类似的问题。可能是由于需要办理护照快递会话中间件。通过以如下顺序使用中间件固定它:(快速4)
var session = require('express-session');
// required for passport session
app.use(session({
secret: 'secrettexthere',
saveUninitialized: true,
resave: true,
// using store session on MongoDB using express-session + connect
store: new MongoStore({
url: config.urlMongo,
collection: 'sessions'
})
}));
// Init passport authentication
app.use(passport.initialize());
// persistent login sessions
app.use(passport.session());
护照的req.isAuthenticated总是返回假的,甚至当我做硬编码(空,真)
我试图让我的护照地方战略的工作。
我有这个中间件设置:
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
正在打印。为什么不工作?
我有一个类似的问题。可能是由于需要办理护照快递会话中间件。通过以如下顺序使用中间件固定它:(快速4)
var session = require('express-session');
// required for passport session
app.use(session({
secret: 'secrettexthere',
saveUninitialized: true,
resave: true,
// using store session on MongoDB using express-session + connect
store: new MongoStore({
url: config.urlMongo,
collection: 'sessions'
})
}));
// Init passport authentication
app.use(passport.initialize());
// persistent login sessions
app.use(passport.session());