And*_*ito 4 authentication mongodb node.js passport-local passport.js
我正在使用 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();
}
}
Run Code Online (Sandbox Code Playgroud)
我想改用以下内容(req.candidate):
function (req, res, next) {
if (!req.candidate) {
req.flash('error', 'Please sign in to access this page.');
res.redirect('/login');
} else {
next();
}
}
Run Code Online (Sandbox Code Playgroud)
您可以在初始化时更改它:
passport.initialize( {
userProperty: 'student' // defaults to 'user' if omitted
})
Run Code Online (Sandbox Code Playgroud)
此代码集:req.student
接下来您要做什么取决于您和所使用的框架。
看源码: Passport源码
| 归档时间: |
|
| 查看次数: |
906 次 |
| 最近记录: |