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

Function validateUserAuthorization

apps/web/src/lib/user/server.ts:1081–1122  ·  view source on GitHub ↗
(
  kiloUserId: string,
  user: User | undefined,
  opts: RequiredPermissions,
  isNewUser?: boolean,
  organizationId?: Organization['id'],
  internalApiUse?: boolean,
  fromDb: typeof db = db,
  botId?: string,
  tokenSource?: string
)

Source from the content-addressed store, hash-verified

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
1090export const nextAuthHttpHandler = NextAuth(authOptions);
1091
1092export type RequiredPermissions = {
1093 adminOnly: boolean;
1094 DANGEROUS_allowBlockedUsers?: boolean;
1095 expectedAudience?: string;
1096};
1097
1098type 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
1120export 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

Callers 1

getUserFromAuthFunction · 0.85

Calls 4

isOrganizationMemberFunction · 0.90
authErrorFunction · 0.85
report_blocked_userFunction · 0.85

Tested by

no test coverage detected