当我的回调路由被调用以进行 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');
});