在护照反序列化功能中重定向用户
Redirect user in passport deserialize function
我在 node/express 应用程序中使用 passport js,我计划根据特定条件在 passport 反序列化中进行响应重定向。我尝试了上面的方法但失败了。
module.exports = function(req, res) {
passport.deserializeUser(function(id, done) {
User.findById(id, function(err, user) {
done(err, user);
});
if(conditions) {
res.redirect('/'); // cannot read property redirect of undefined
}
});
}
不,您不能在 deserializeUser
中使用 res
,因为那里不可用。如果反序列化成功并找到用户,您只有 done
回调告诉 Passport。也许你可以打电话给 done(null, null)
?
我在 node/express 应用程序中使用 passport js,我计划根据特定条件在 passport 反序列化中进行响应重定向。我尝试了上面的方法但失败了。
module.exports = function(req, res) {
passport.deserializeUser(function(id, done) {
User.findById(id, function(err, user) {
done(err, user);
});
if(conditions) {
res.redirect('/'); // cannot read property redirect of undefined
}
});
}
不,您不能在 deserializeUser
中使用 res
,因为那里不可用。如果反序列化成功并找到用户,您只有 done
回调告诉 Passport。也许你可以打电话给 done(null, null)
?