节点JS passport.authenticate始终返回false

时间:2017-07-20 03:56:18

标签: node.js express

我对节点js很新,并希望在此开始一个项目。所以我一直关注这个链接 -  email field is optional in passportjs facebook strategy - 为了确保在Facebook身份验证期间电子邮件字段是强制性的。它运行良好,当用户取消选中电子邮件字段时,它会将用户重定向到同一页面,直到用户检查该字段。但是,当用户继续检查电子邮件字段时,isAuthenticated()始终返回false,因此重定向到“/ login”而不是“/ account”。我该怎么写才能解决问题?附件是我的代码的片段。提前谢谢。

<?php } ?>

用于回调,

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;
       } 

在'/ account',

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) });

ensureAuthenticated函数:

    app.get('/account', ensureAuthenticated, function(req, res){
    res.render('account', { user: req.user });
    });

0 个答案:

没有答案
相关问题