我正在使用Passport.js,但当我进入其他地方时,如果它给了我未经授权的错误。我们在这里打电话给网络服务。当我进入其他如果(存在)时,我想发送响应oto webservice。有什么想法吗?
passport.use('local-signup-nti', new LocalStrategy({
// by default, local strategy uses username and password, we will override with email
usernameField: 'email',
passwordField: 'password',
passReqToCallback: true // allows us to pass back the entire request to the callback
},
function (req, email, password, done) {
user.emailExists(email, function (err, exists) {
if (err)
return done(err);
else if (exists) {
req.userDetails=1;
return done(err, req.userDetails);
} else {
}
答案 0 :(得分:0)
必须始终调用done
函数,否则,护照将无法正常工作。
因此,您必须将结果传递给done
函数并传递回调passport.authenticate
函数以按您希望的方式处理结果。
参见示例:
app.get('/protected', function(req, res, next) {
passport.authenticate('local-signup-nti', function(err, user, info) {
if (err) { return next(err) }
if (!user) { return res.redirect('/whereEverYouWant') }
res.redirect('/toYourWebService');
})(req, res, next);
});
希望它清楚!