Skip to content

Commit

Permalink
fix: SAML fixes for uppercase email & GOOGLE → SAML idp switch (#14971)
Browse files Browse the repository at this point in the history
* fix uppercase email slip

* fix google → SAML idp change
  • Loading branch information
alishaz-polymath committed May 10, 2024
1 parent 039bf6d commit b190933
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/features/auth/lib/next-auth-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ if (isSAMLLoginEnabled) {
return null;
}

const { id, firstName, lastName, email } = userInfo;
const { id, firstName, lastName } = userInfo;
const email = userInfo.email.toLowerCase();
let user = !email
? undefined
: await UserRepository.findByEmailAndIncludeProfilesAndPassword({ email });
Expand Down Expand Up @@ -844,7 +845,7 @@ export const AUTH_OPTIONS: AuthOptions = {
where: { email: existingUserWithEmail.email },
// also update email to the IdP email
data: {
email: user.email,
email: user.email.toLowerCase(),
identityProvider: idP,
identityProviderId: account.providerAccountId,
},
Expand All @@ -857,6 +858,19 @@ export const AUTH_OPTIONS: AuthOptions = {
}
} else if (existingUserWithEmail.identityProvider === IdentityProvider.CAL) {
return "/auth/error?error=use-password-login";
} else if (
existingUserWithEmail.identityProvider === IdentityProvider.GOOGLE &&
idP === IdentityProvider.SAML
) {
await prisma.user.update({
where: { email: existingUserWithEmail.email },
// also update email to the IdP email
data: {
email: user.email.toLowerCase(),
identityProvider: idP,
identityProviderId: account.providerAccountId,
},
});
}

return "/auth/error?error=use-identity-login";
Expand Down

0 comments on commit b190933

Please sign in to comment.