0

当我的回调路由被调用以进行 Google 登录时,我遇到了500 Internal Server服务器错误,我不确定我的代码的哪一部分导致了这个问题。从我的终端结果中可以看出,它正在传递 if 语句条件并触发正在响应和输出的 cb 函数[object SequelizeInstance:external_account]。输出可能是不正确的值吗?我不确定电话应该接受什么价值。

控制台日志:

If statement was true externalId and Email present
GET /auth/google/callback?code=4/mvFTIURH5P0ACQFwZobC04-ftehalfdf4454 500 434.737 ms - 44
[object SequelizeInstance:external_account]

PassportJS 设置:

/*====  Google Configuration  ====*/

passport.use(new GoogleStrategy({
    clientID: 'client-id',
    clientSecret: 'client-secret',
    callbackURL: 'http://localhost:3000/auth/google/callback'
  }, function(accessToken, refreshToken, profile, cb) {
        var user;
        models.User.findOne({
            where: {
                email: profile.emails[0].value
            }
        }).then(function(_user){
            user = _user;
            return models.ExternalAccount.findOne({
                where: {
                    externalSourceId: profile.id
                }
            }).then(function(externalAccount, err){
                if(user && externalAccount){
                console.log("If statement was true externalId and Email present");
                return cb(externalAccount, err)
            } else if (user){
                console.log("Else If statement was true Email was present, but no account Id");
                return models.ExternalAccount.create({
                    externalSource: "Google",
                    externalSourceId: externalAccount.externalSourceId,
                    userId: externalAccount.user.id
                }).then(function(){
                    return cb(externalAccount, err)
                });
            } else {
                console.log('Error');
            }
            })
        })
  }));

路线:

/*====  /AUTH/GOOGLE  ====*/

siteRoutes.route('/auth/google') 
    .get(passport.authenticate('google', { scope: ['profile', 'email'] }));

/*====  /AUTH/GOOGLE/CALLBACK  ====*/

siteRoutes.route('/auth/google/callback') 
    .get(passport.authenticate('google', {
            successRedirect : '/app',
            failureRedirect : '/login',
            failureFlash: 'Invalid Google credentials.'
        }),function(req, res){
        res.redirect('/app');
    });
4

1 回答 1

0

如果您不使用 https,则可能从 google 的服务器发生错误。Google 登录 api 仅接受使用 ssl 的安全网络。尝试使用 ssl。如果你仍然在这个问题上......

于 2020-09-14T05:57:05.320 回答