我正在设置一个基本的管理员身份验证,当用户登录时,我在 authcallback 中调用此函数:
function checkAdmin (req) {
Admin.findOne( { user : req.user.id },function ( err, admin, count ){
req.session.isAdmin = true;
console.log("session : %j",req.session);
})
}
然后我做
res.redirect('/')
索引控制器内的代码:
console.log("session : %j",req.session);
res.render('index', { title: 'Accueil',message: req.flash('info') });
这就是我在控制台中得到的:
session : {"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path"
:"/"},"passport":{"user":"5079832df1e9a6485e000001"},"flash":{},"isAdmin":true}
session : {"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path"
:"/"},"passport":{"user":"5079832df1e9a6485e000001"},"flash":{}}
我不明白为什么会话不存储 isAdmin 值。
我读过一些其他问题,说 app.use(app.router) 地方可能是一个原因,但我确实这样做了:
app.use(cookieParser)
app.use(express.session({store: session_store }));
app.use(passport.initialize())
app.use(passport.session())
// routes should be at the last
app.use(app.router)
我猜这一定是个白痴..