更新时间:2023-09-29 08:10:34
在你的验证回调中,我会改变一切 findOrCreateUser
函数将实际记录提供给回调,然后将其传递到 done()
,如此:
In your verify callback, I would change things up so that the findOrCreateUser
function supplies the actual record to the callback, and then pass that through to done()
, like so:
Models_User.findOrCreateUser(profile, function(user){
console.log("auth type:" + msg);
return done(null, user);
});
// take this out, use the actual model above
//return done(null, profile);
现在,在验证后处理回调URL时,您可以检查此用户记录,看看是否new(我假设它有一个isNew属性在这里):
Now, when handling the callback URL after authentication, you can check this user record and see if it was new (I'm assuming it has an isNew property here):
app.get('/auth/github/callback',
passport.authenticate('github', { failureRedirect: '/login' }),
function(req, res) {
// successful auth, user is set at req.user. redirect as necessary.
if (req.user.isNew) { return res.redirect('/back_again'); }
res.redirect('/welcome');
});