【发布时间】:2016-12-13 16:48:08
【问题描述】:
在passportJS文档中,我认为passport isAuthenticated功能没有很好地记录。
PassportJS 中的req.isAuthenticated() 是如何实现的?
【问题讨论】:
标签: node.js passport.js
在passportJS文档中,我认为passport isAuthenticated功能没有很好地记录。
PassportJS 中的req.isAuthenticated() 是如何实现的?
【问题讨论】:
标签: node.js passport.js
对于任何请求,您都可以使用此方法检查用户是否已通过身份验证。
app.get('/some_path',checkAuthentication,function(req,res){
//do something only if user is authenticated
});
function checkAuthentication(req,res,next){
if(req.isAuthenticated()){
//req.isAuthenticated() will return true if user is logged in
next();
} else{
res.redirect("/login");
}
}
【讨论】:
req.session.passport.user !== undefined 对吗?