node.js 什么是 req.isAuthenticated() 护照JS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38820251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 20:28:22 来源:igfitidea点击:
what is req.isAuthenticated() passportJS
提问by Kim
In passportJS Documention, I think passport authenticated function not documented well.
在passportJS Documention 中,我认为护照验证功能没有很好地记录。
I want to ask, what passport.isAuthenticated() id do?
我想问一下,passport.isAuthenticated() id是做什么的?
回答by Anurag Awasthi
For any request you can check if a user is authenticated or not using this method.
对于任何请求,您都可以使用此方法检查用户是否已通过身份验证。
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");
}
}

