MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / jwt

Function jwt

apps/web/src/lib/user/server.ts:893–939  ·  view source on GitHub ↗
({ token, account, user, trigger, profile })

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

findAndSyncExistingUserFunction · 0.90
getLowerDomainFromEmailFunction · 0.90
createAccountInfoFunction · 0.85
errorMethod · 0.65

Tested by

no test coverage detected