繁体   English   中英

PassportJS重命名“用户”对象

[英]PassportJS rename “user” object

我正在使用PassportJS登录我的登录功能是否有办法在请求中更改“用户”对象名称?

现在这是它的工作原理,默认情况下(req.user):

function (req, res, next) {
    if (!req.user) {
        req.flash('error', 'Please sign in to access this page.');
        res.redirect('/login');
    } else {
        next();
    }
}

我想使用以下代码(req.candidate):

function (req, res, next) {
    if (!req.candidate) {
        req.flash('error', 'Please sign in to access this page.');
        res.redirect('/login');
    } else {
        next();
    }
}

您可以在初始化中更改它:

 passport.initialize( {
      userProperty: 'student' // defaults to 'user' if omitted
     })

此代码集: req.student

您接下来要做什么取决于您和使用的框架。

查看源代码: Passport源代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM