小编典典

什么是req.isAuthenticated()护照JS

node.js

在passportJS Documention中,我认为护照认证功能记录得不好。

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


阅读 388

收藏
2020-07-07

共1个答案

小编典典

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

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");
    }
}
2020-07-07