什么是req.isAuthenticated()护照 [英] what is req.isAuthenticated() passportJS

查看:130
本文介绍了什么是req.isAuthenticated()护照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在"passportJS文档"中,我认为护照认证功能记录得不好.

In passportJS Documention, I think passport authenticated function not documented well.

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

I want to ask, what passport.isAuthenticated() id do?

推荐答案

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

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

这篇关于什么是req.isAuthenticated()护照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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