Check if there is already an account that isn't linked to a google account but uses the google accounts email address
This commit is contained in:
@ -191,6 +191,11 @@ passport.use(new GoogleStrategy(secrets.google, function(req, accessToken, refre
|
||||
} else {
|
||||
User.findOne({ google: profile.id }, function(err, existingUser) {
|
||||
if (existingUser) return done(null, existingUser);
|
||||
User.findOne({ email: profile._json.email }, function(err2, existingEmailUser) {
|
||||
if(existingEmailUser) {
|
||||
req.flash('errors', { msg: 'There is already an account using this google account\'s email address, login and link your account to your google account from account settings' });
|
||||
done(err2);
|
||||
} else {
|
||||
var user = new User();
|
||||
user.email = profile._json.email;
|
||||
user.google = profile.id;
|
||||
@ -201,6 +206,8 @@ passport.use(new GoogleStrategy(secrets.google, function(req, accessToken, refre
|
||||
user.save(function(err) {
|
||||
done(err, user);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
Reference in New Issue
Block a user