(request: Request)
| 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)), |
nothing calls this directly
no test coverage detected