sign in to existing email account with new google sign-in

This commit is contained in:
lingdocs 2021-09-16 10:41:26 -04:00
parent 271df7f2fd
commit f9b239657c
1 changed files with 7 additions and 0 deletions

View File

@ -62,6 +62,13 @@ function setupPassport(passport: PassportStatic) {
if (otherAccountWSameGoogle) {
return done(null, otherAccountWSameGoogle);
}
// if the person used their google email for a plain signup, add the google provider to it and sign in
const googleMail = profile.emails && profile.emails[0].value;
if (googleMail) {
const otherAccountWSameEmail = await getLingdocsUser("email", googleMail);
otherAccountWSameEmail && await updateLingdocsUser(otherAccountWSameEmail?.userId, { google: gProfile });
return done(null, otherAccountWSameEmail);
}
const u = await updateLingdocsUser(req.user.userId, { google: gProfile });
if (!u.email) {
// if the user is adding a google account and doesn't have a previous email, add the google email