({ token, account, user, trigger, profile })
| 891 | let linkingSession: AccountLinkingSession | null = null; |
| 892 | const redirectContext = await getSignInRedirectContext(); |
| 893 | const redirectUrlForCode = (error: AuthErrorType): string => { |
| 894 | const redirectUrl = new URL( |
| 895 | authFailureRedirectUrl(error, Boolean(isAccountLinking)), |
| 896 | 'http://localhost' |
| 897 | ); |
| 898 | if (!isAccountLinking) { |
| 899 | if (redirectContext.callbackPath) { |
| 900 | redirectUrl.searchParams.set('callbackPath', redirectContext.callbackPath); |
| 901 | } |
| 902 | if (redirectContext.signup) { |
| 903 | redirectUrl.searchParams.set('signup', 'true'); |
| 904 | } |
| 905 | } |
| 906 | return `${redirectUrl.pathname}?${redirectUrl.searchParams.toString()}`; |
| 907 | }; |
| 908 | try { |
| 909 | if (!account) return `TRAP: No account found`; |
| 910 | |
| 911 | // early return for fake auth |
| 912 | const isFakeLogin = account.provider === 'fake-login'; |
| 913 | if (isFakeLogin && !allow_fake_login) |
| 914 | return 'Fake login is not available in production mode'; |
| 915 | |
| 916 | // early return for email auth (magic link) |
| 917 | const isEmailAuth = account.provider === 'email'; |
| 918 | |
| 919 | // normalize the account, user, and profile objects into a single object |
| 920 | // why does next-auth have 3 separate objects for this? who knows. |
| 921 | accountInfo = createAccountInfo(account, user, profile); |
| 922 | |
| 923 | linkingSession = await getAccountLinkingSession(); |
| 924 | |
| 925 | isAccountLinking = linkingSession && linkingSession.targetProvider === accountInfo.provider; |
| 926 | |
| 927 | // if a user's email domain matches any organization's SSO domain and they are not logging in with SSO, force them to use SSO immediately |
| 928 | const domain = getLowerDomainFromEmail(accountInfo.google_user_email); |
| 929 | |
| 930 | if (!domain) { |
| 931 | return redirectUrlForCode('USER-NOT-FOUND'); |
| 932 | } |
| 933 | |
| 934 | if (await isEmailBlacklistedByDomainAsync(accountInfo.google_user_email)) { |
| 935 | sentryLogger('auth', 'warning')( |
| 936 | `SECURITY: Blacklisted: ${accountInfo.google_user_email}`, |
| 937 | accountInfo |
| 938 | ); |
| 939 | |
| 940 | return redirectUrlForCode(`BLOCKED`); |
| 941 | } |
| 942 |
nothing calls this directly
no test coverage detected