Scheduling infrastructure for absolutely everyone.
fix: SAML fixes for uppercase email & GOOGLE → SAML idp switch (#14971)
Syed Ali Shahbazb1909337dbd9
diff --git a/packages/features/auth/lib/next-auth-options.ts b/packages/features/auth/lib/next-auth-options.tsindex 5f391a66df4..a0bf241de0f 100644--- a/packages/features/auth/lib/next-auth-options.ts+++ b/packages/features/auth/lib/next-auth-options.ts@@ -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 });@@ -844,7 +845,7 @@ export const AUTH_OPTIONS: AuthOptions = {where: { email: existingUserWithEmail.email },// also update email to the IdP emaildata: {- email: user.email,+ email: user.email.toLowerCase(),identityProvider: idP,identityProviderId: account.providerAccountId,},@@ -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";