( kiloUserId: string, user: User | undefined, opts: RequiredPermissions, isNewUser?: boolean, organizationId?: Organization['id'], internalApiUse?: boolean, fromDb: typeof db = db, botId?: string, tokenSource?: string )
| 1079 | session.ssoSourceOrganizationId = castToken.ssoSourceOrganizationId; |
| 1080 | return session; |
| 1081 | }, |
| 1082 | }, |
| 1083 | pages: { |
| 1084 | signIn: '/users/sign_in', |
| 1085 | error: '/users/sign_in', |
| 1086 | }, |
| 1087 | debug: !!getEnvVariable('DEBUG_AUTH'), |
| 1088 | }; |
| 1089 | |
| 1090 | export const nextAuthHttpHandler = NextAuth(authOptions); |
| 1091 | |
| 1092 | export type RequiredPermissions = { |
| 1093 | adminOnly: boolean; |
| 1094 | DANGEROUS_allowBlockedUsers?: boolean; |
| 1095 | expectedAudience?: string; |
| 1096 | }; |
| 1097 | |
| 1098 | type GetAuthResponse = |
| 1099 | | { |
| 1100 | user: null; |
| 1101 | authFailedResponse: NextResponse<FailureResult<string>>; |
| 1102 | isNewUser?: undefined; |
| 1103 | organizationId?: undefined; |
| 1104 | internalApiUse?: undefined; |
| 1105 | botId?: undefined; |
| 1106 | tokenSource?: undefined; |
| 1107 | deviceSessionId?: undefined; |
| 1108 | } |
| 1109 | | { |
| 1110 | user: User; |
| 1111 | authFailedResponse: null; |
| 1112 | isNewUser?: boolean; |
| 1113 | organizationId?: Organization['id']; |
| 1114 | internalApiUse?: boolean; |
| 1115 | botId?: string; |
| 1116 | tokenSource?: string; |
| 1117 | deviceSessionId?: string; |
| 1118 | }; |
| 1119 | |
| 1120 | export async function getUserFromAuth(opts: RequiredPermissions): Promise<GetAuthResponse> { |
| 1121 | const headersList = await headers(); |
| 1122 | const result = await resolveUserFromAuth(opts, headersList); |
| 1123 | |
| 1124 | // Admin audit trail: emit exactly one identity-attributed event per authorized |
| 1125 | // admin request. Guarded strictly on adminOnly so the millions of |
no test coverage detected