From d55d1e3d38ecd4bdac9b7b686d4bac8a3e1158ed Mon Sep 17 00:00:00 2001 From: Donald Silveira Date: Wed, 2 Dec 2026 11:39:33 -0300 Subject: [PATCH] fix(auth): let clients sign in with a client metadata document on Workers Better Auth's CIMD fetch asks for `redirect: 'error'`, which workerd's Request rejects, so every metadata URL client (Executor) failed with invalid_client. The Workers transport now uses `manual`, which keeps redirects unfollowed. Co-Authored-By: Claude Opus 5.5 --- src/platform/cloudflare/auth.server.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/platform/cloudflare/auth.server.ts b/src/platform/cloudflare/auth.server.ts index ac02e63..b5636df 100644 --- a/src/platform/cloudflare/auth.server.ts +++ b/src/platform/cloudflare/auth.server.ts @@ -9,15 +9,18 @@ export const authPlatform: AuthPlatform = { // reach a private network. A Worker has no private network to reach: its // fetches leave through Cloudflare to the public internet. The rest of the // contract (HTTPS, GET or HEAD, redirects returned unfollowed) holds here. + // CIMD asks for `redirect: 'error'`, which workerd's Request rejects, so + // the redirect is replaced by `manual`: a 3xx comes back as a non-200 that + // CIMD refuses. fetchClientMetadataResource: (input, init) => { - const request = new Request(input, init) + const request = new Request(input, { ...init, redirect: 'manual' }) if (new URL(request.url).protocol !== 'https:') { throw new TypeError('CIMD metadata must be fetched over HTTPS') } if (request.method !== 'GET' && request.method !== 'HEAD') { throw new TypeError('CIMD metadata is fetched with GET or HEAD only') } - return fetch(request, { redirect: 'manual' }) + return fetch(request) }, // Comparing the schema takes four D1 round trips, and every new isolate // would pay them before reading a session. The configuration only changes