Passport JS 中的 req.isAuthenticated() 是如何实现的?
How is req.isAuthenticated() in Passport JS implemented?
在 passportJS 文档中,我认为 passport isAuthenticated
功能没有很好地记录。
PassportJS中的req.isAuthenticated()
是如何实现的?
对于任何请求,您都可以使用此方法检查用户是否已通过身份验证。
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");
}
}
在 passportJS 文档中,我认为 passport isAuthenticated
功能没有很好地记录。
PassportJS中的req.isAuthenticated()
是如何实现的?
对于任何请求,您都可以使用此方法检查用户是否已通过身份验证。
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");
}
}