From 550d885eb90fd156add7b93bbdc54d30d2f9a98d Mon Sep 17 00:00:00 2001 From: Hans Otto Wirtz Date: Tue, 20 Aug 2024 14:23:32 +0200 Subject: [PATCH] fix(fetch): fix credentials handling in Cloudflare workers (#6533) Co-authored-by: Dmitriy Mozgovoy --- lib/adapters/fetch.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/adapters/fetch.js b/lib/adapters/fetch.js index f997f1d..e52fa38 100644 --- a/lib/adapters/fetch.js +++ b/lib/adapters/fetch.js @@ -155,6 +155,9 @@ export default isFetchSupported && (async (config) => { withCredentials = withCredentials ? 'include' : 'omit'; } + // Cloudflare Workers throws when credentials are defined + // see https://github.com/cloudflare/workerd/issues/902 + const isCredentialsSupported = "credentials" in Request.prototype; request = new Request(url, { ...fetchOptions, signal: composedSignal, @@ -162,7 +165,7 @@ export default isFetchSupported && (async (config) => { headers: headers.normalize().toJSON(), body: data, duplex: "half", - credentials: withCredentials + credentials: isCredentialsSupported ? withCredentials : undefined }); let response = await fetch(request);