From f9b239657c4f41c97f20a3c7089f4cc4f30d5563 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Thu, 16 Sep 2021 10:41:26 -0400 Subject: [PATCH] sign in to existing email account with new google sign-in --- account/src/middleware/setup-passport.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/account/src/middleware/setup-passport.ts b/account/src/middleware/setup-passport.ts index 4b05f94..3323468 100644 --- a/account/src/middleware/setup-passport.ts +++ b/account/src/middleware/setup-passport.ts @@ -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