什么是req.isAuthenticated()passportJS

时间:2016-08-08 01:49:35

标签: node.js passport.js

在passportJS文件中,我认为护照认证功能没有记录良好。

我想问一下,passport.isAuthenticated()id是做什么的?

1 个答案:

答案 0 :(得分:62)

对于任何请求,您可以使用此方法检查用户是否已通过身份验证。

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");
    }
}
相关问题