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

Function withOptionalAuth

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

Source from the content-addressed store, hash-verified

46};
47
48export const withOptionalAuth = async <T>(fn: (params: OptionalAuthContext) => Promise<T>) => {
49 const authContext = await getAuthContext();
50 if (isServiceError(authContext)) {
51 return authContext;
52 }
53
54 if (
55 (!authContext.user || !authContext.role) &&
56 !(await isAnonymousAccessEnabled())
57 ) {
58 return notAuthenticated();
59 }
60
61 return fn(authContext);
62};
63
64export const getAuthContext = async (): Promise<OptionalAuthContext | ServiceError> => {
65 const authResult = await getAuthenticatedUser();

Callers 15

getReposFunction · 0.90
getReposStatsFunction · 0.90
getRepoInfoByNameFunction · 0.90
getSearchContextsFunction · 0.90
getRepoImageFunction · 0.90
authenticatedPageFunction · 0.90
withAuth.test.tsFile · 0.90
translateSearchQueryFunction · 0.90
getFileSourceFunction · 0.90
getFilesFunction · 0.90
getFileBlameFunction · 0.90
getDiffFunction · 0.90

Calls 4

isServiceErrorFunction · 0.90
isAnonymousAccessEnabledFunction · 0.90
notAuthenticatedFunction · 0.90
getAuthContextFunction · 0.85

Tested by

no test coverage detected