Node.js Node JS passport.authenticate始终返回false
我对node js非常陌生,希望在这方面启动一个项目。所以我一直在关注这个链接- -为了确保在Facebook身份验证期间电子邮件字段是必需的。当用户取消选中电子邮件字段时,它会将用户重定向到同一页面,直到用户选中该字段为止。但是,当用户继续选中电子邮件字段时,isAuthenticated()始终返回false,从而重定向到“/login”而不是“/account”。我应该怎样写才能解决这个问题?附件是我的代码片段。先谢谢你Node.js Node JS passport.authenticate始终返回false,node.js,express,Node.js,Express,我对node js非常陌生,希望在这方面启动一个项目。所以我一直在关注这个链接- -为了确保在Facebook身份验证期间电子邮件字段是必需的。当用户取消选中电子邮件字段时,它会将用户重定向到同一页面,直到用户选中该字段为止。但是,当用户继续选中电子邮件字段时,isAuthenticated()始终返回false,从而重定向到“/login”而不是“/account”。我应该怎样写才能解决这个问题?附件是我的代码片段。先谢谢你 passport.use(new FacebookStrategy(
passport.use(new FacebookStrategy({
clientID: config.facebook_api_key,
clientSecret:config.facebook_api_secret ,
callbackURL: config.facebook_callback_url,
profileFields: ['id', 'emails', 'displayName']
},function(accessToken, refreshToken, profile, done) {
if (profile.emails === undefined){
done('email-required')
return;
}
对于回调
app.get('/auth/facebook/callback', function(req, res, next) {
passport.authenticate('facebook', function (err) {
console.log('this is error '+ err);
if (err) {
if (err == 'email-required') res.redirect('/auth/facebook');
// check for other kinds of errors and show proper messages
return;
}else{
res.redirect('/account');
}
})(req, res, next) });
在“/帐户”处
app.get('/account', ensureAuthenticated, function(req, res){
res.render('account', { user: req.user });
});
确保重新验证的功能:
function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) {
return next();
}
res.redirect('/login')
}