From 9146cba0bcbfe61e0c6233f7b8c9443f6a9ed8cf Mon Sep 17 00:00:00 2001 From: manchenkoff Date: Wed, 19 Jun 2024 00:10:40 +0200 Subject: [PATCH] fix: experimental support for cloudflare workers --- src/runtime/httpFactory.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/runtime/httpFactory.ts b/src/runtime/httpFactory.ts index ff3014a..e4a9d19 100644 --- a/src/runtime/httpFactory.ts +++ b/src/runtime/httpFactory.ts @@ -35,6 +35,17 @@ function configureClientInterceptors( } } +function determineCredentialsMode() { + // Fix for Cloudflare workers - https://github.com/cloudflare/workers-sdk/issues/2514 + const isCredentialsSupported = 'credentials' in Request.prototype; + + if (!isCredentialsSupported) { + return undefined; + } + + return 'include'; +} + export function createHttpClient(logger: ConsolaInstance): $Fetch { const options = useSanctumConfig(); const user = useSanctumUser(); @@ -53,7 +64,7 @@ export function createHttpClient(logger: ConsolaInstance): $Fetch { const httpOptions: FetchOptions = { baseURL: options.baseUrl, - credentials: 'include', + credentials: determineCredentialsMode(), redirect: 'manual', retry: options.client.retry,