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

Function getAuthToken

apps/web/src/scripts/lib/auth.ts:10–45  ·  view source on GitHub ↗
(
  organizationId: string,
  extraPayload?: JWTTokenExtraPayload
)

Source from the content-addressed store, hash-verified

8 * Fetches the first user in the organization and generates an auth token
9 */
10export async function getAuthToken(
11 organizationId: string,
12 extraPayload?: JWTTokenExtraPayload
13): Promise<string> {
14 // Get the first member of the organization
15 const memberships = await db
16 .select({
17 kilo_user_id: organization_memberships.kilo_user_id,
18 })
19 .from(organization_memberships)
20 .where(eq(organization_memberships.organization_id, organizationId))
21 .limit(1);
22
23 if (memberships.length === 0) {
24 throw new Error(`No members found in organization ${organizationId}`);
25 }
26
27 const userId = memberships[0].kilo_user_id;
28
29 // Get the user details
30 const users = await db
31 .select()
32 .from(kilocode_users)
33 .where(eq(kilocode_users.id, userId))
34 .limit(1);
35
36 if (users.length === 0) {
37 throw new Error(`User ${userId} not found`);
38 }
39
40 const user = users[0];
41
42 // Generate API token
43 const token = generateApiToken(user, extraPayload);
44 return token;
45}

Callers 2

getAuthConfigFunction · 0.90
getAuthConfigFunction · 0.90

Calls 2

generateApiTokenFunction · 0.90
limitMethod · 0.65

Tested by

no test coverage detected