MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / authHandler

Function authHandler

apps/host-selfhost/src/auth/index.ts:68–83  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

66 // resulting consent redirect with the registered client name.
67 const config = loadConfig();
68 const authHandler = async (request: Request): Promise<Response> => {
69 const response = await betterAuth.handler(withForcedMcpConsent(request));
70 // Turn Better Auth's bare 403 "Invalid origin" into a setup instruction —
71 // on a fresh deploy it almost always means the public URL needs configuring.
72 const friendlier = await rewriteInvalidOrigin(request, response, config.webBaseUrl);
73 if (friendlier) return friendlier;
74 if (response.status !== 302) return response;
75 const clientId = consentRedirectClientId(response.headers.get("location"));
76 if (!clientId) return response;
77 const name = await lookupClientName(clientId);
78 if (!name) return response;
79 // Preserve the rest of the response — notably the signed consent cookie.
80 const headers = new Headers(response.headers);
81 headers.set("location", withClientName(response.headers.get("location")!, name));
82 return new Response(null, { status: 302, headers });
83 };
84
85 return {
86 identityLayer: betterAuthIdentityLayer.pipe(Layer.provide(betterAuthLayer)),

Callers

nothing calls this directly

Calls 7

withForcedMcpConsentFunction · 0.90
rewriteInvalidOriginFunction · 0.90
consentRedirectClientIdFunction · 0.90
withClientNameFunction · 0.90
lookupClientNameFunction · 0.85
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected