Passport JS 中的 req.isAuthenticated() 是如何实现的? [英] How is req.isAuthenticated() in Passport JS implemented?

查看:52
本文介绍了Passport JS 中的 req.isAuthenticated() 是如何实现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在passportJS 文档中,我认为passport isAuthenticated 功能没有很好地记录.

In passportJS Documentation, I think passport isAuthenticated function not documented well.

PassportJS 中的 req.isAuthenticated() 是如何实现的?

How is req.isAuthenticated() in PassportJS implemented?

推荐答案

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

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

这篇关于Passport JS 中的 req.isAuthenticated() 是如何实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆