MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / withAuth

Function withAuth

packages/web/src/middleware/withAuth.ts:32–46  ·  view source on GitHub ↗
(fn: (params: RequiredAuthContext) => Promise<T>)

Source from the content-addressed store, hash-verified

30
31
32export const withAuth = async <T>(fn: (params: RequiredAuthContext) => Promise<T>) => {
33 const authContext = await getAuthContext();
34
35 if (isServiceError(authContext)) {
36 return authContext;
37 }
38
39 const { user, org, role, prisma } = authContext;
40
41 if (!user || !role) {
42 return notAuthenticated();
43 }
44
45 return fn({ user, org, role, prisma });
46};
47
48export const withOptionalAuth = async <T>(fn: (params: OptionalAuthContext) => Promise<T>) => {
49 const authContext = await getAuthContext();

Callers 15

completeOnboardingFunction · 0.90
createApiKeyFunction · 0.90
deleteApiKeyFunction · 0.90
getUserApiKeysFunction · 0.90
getConnectionStatsFunction · 0.90
authenticatedPageFunction · 0.90
withAuth.test.tsFile · 0.90
removeMemberFromOrgFunction · 0.90
leaveOrgFunction · 0.90
rejectAccountRequestFunction · 0.90
approveAccountRequestFunction · 0.90
createInvitesFunction · 0.90

Calls 3

isServiceErrorFunction · 0.90
notAuthenticatedFunction · 0.90
getAuthContextFunction · 0.85

Tested by

no test coverage detected