PassportJS重命名“用户”对象
我使用PassportJS作为我的loginfunction有没有办法改变请求中的“用户”对象名称?
这是现在它是如何工作的,默认情况下(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源代码
- Node.js https pem错误:例程:PEM_read_bio:没有开始行
- 适用于移动Web服务的Bluemix SSO
- ReferenceError:请求没有在NodeJS Session中定义
- 在OAuth 2.0安全Web应用程序上使用JMeter脚本进行性能testing
- bluemix无法login,停止/重新启动应用程序
- 如何…使用Google / Facebook OAuthlogin和Google Checkout来pipe理js
- 在Nodejs中没有关于任何其他用户的最新发布信息
- 如何使用Node.js和Passport进行身份validation后,使用自己的ID将用户redirect到主页?
- 如何使用Passport.js访问Cookie