supabase-js: The 'cache' field on 'RequestInitializerDict' is not implemented - Cloudflare Workers

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When using the following method

supabase.auth.getUser(jwt?: string)

in my wrangler clouflare workers api I get following error:

  --> POST /jwt/plan/current/55524767-a973-410f-b139-3794d4efbb2e 401 1ms
✘ [ERROR] Error: The 'cache' field on 'RequestInitializerDict' is not implemented.

      at checkURL
  (file:///Users/david/Documents/github/vinna-ai/api/app/.wrangler/tmp/bundle-ieatTC/checked-fetch.js:9:9)
      at Object.apply
  (file:///Users/david/Documents/github/vinna-ai/api/app/.wrangler/tmp/bundle-ieatTC/checked-fetch.js:27:3)
      at null.<anonymous>
  (file:///Users/david/Documents/github/vinna-ai/api/app/node_modules/@supabase/auth-js/src/lib/helpers.ts:103:23)
      at _handleRequest
  (file:///Users/david/Documents/github/vinna-ai/api/app/node_modules/@supabase/auth-js/src/lib/fetch.ts:178:20)
      at _request
  (file:///Users/david/Documents/github/vinna-ai/api/app/node_modules/@supabase/auth-js/src/lib/fetch.ts:151:22)
      at SupabaseAuthClient._getUser
  (file:///Users/david/Documents/github/vinna-ai/api/app/node_modules/@supabase/auth-js/src/GoTrueClient.ts:1188:22)
      at SupabaseAuthClient.getUser
  (file:///Users/david/Documents/github/vinna-ai/api/app/node_modules/@supabase/auth-js/src/GoTrueClient.ts:1168:25)
      at authSupabaseMiddleware
  (file:///Users/david/Documents/github/vinna-ai/api/app/src/middleware/authSupabase.ts:35:56)
      at dispatch
  (file:///Users/david/Documents/github/vinna-ai/api/app/node_modules/hono/dist/compose.js:29:23)
      at null.<anonymous>
  (file:///Users/david/Documents/github/vinna-ai/api/app/node_modules/hono/dist/compose.js:30:20)
  Error while getting user by access_token  AuthRetryableFetchError: The 'cache' field on
  'RequestInitializerDict' is not implemented.
      at _handleRequest
  (file:///Users/david/Documents/github/vinna-ai/api/app/node_modules/@supabase/auth-js/src/lib/fetch.ts:188:11)
      at _request
  (file:///Users/david/Documents/github/vinna-ai/api/app/node_modules/@supabase/auth-js/src/lib/fetch.ts:151:22)
      at SupabaseAuthClient._getUser
  (file:///Users/david/Documents/github/vinna-ai/api/app/node_modules/@supabase/auth-js/src/GoTrueClient.ts:1188:22)
      at SupabaseAuthClient.getUser
  (file:///Users/david/Documents/github/vinna-ai/api/app/node_modules/@supabase/auth-js/src/GoTrueClient.ts:1168:25)
      at authSupabaseMiddleware
  (file:///Users/david/Documents/github/vinna-ai/api/app/src/middleware/authSupabase.ts:35:56)
      at dispatch
  (file:///Users/david/Documents/github/vinna-ai/api/app/node_modules/hono/dist/compose.js:29:23)
      at null.<anonymous>
  (file:///Users/david/Documents/github/vinna-ai/api/app/node_modules/hono/dist/compose.js:30:20)
      at defaultMiddleware
  (file:///Users/david/Documents/github/vinna-ai/api/app/src/middleware/default.ts:87:9)
      at dispatch
  (file:///Users/david/Documents/github/vinna-ai/api/app/node_modules/hono/dist/compose.js:29:23)
      at null.<anonymous>
  (file:///Users/david/Documents/github/vinna-ai/api/app/node_modules/hono/dist/compose.js:30:20) {
    __isAuthError: true,
    status: 0,
    code: undefined
  }

To Reproduce

I am using wrangler cloudflare worker and I am using hono for routing, but either way these lines should trigger the error:

const jwt: string = c.req.header("Authorization")?.split(" ")[1] ?? "";
const { data, error } = await supabase.auth.getUser(jwt);

After that data is null and error includes the error, which is pasted above.

Expected behavior

It should just get the user as usual, this problem occurred just since today for me.

Screenshots

  • None

System information

  • OS: macOS (Verified it also does not work when deployed to cloudflare workers)
  • Version of supabase-js: [2.41.1] also for (2.38.0)
  • Version of Node.js: [21.6.2]

Additional context

Also not sure if its an issue from cloudflare wrangler itself. Reference to issue: https://github.com/cloudflare/workerd/issues/698

Would be cool to know if there is anything I can do, since I am not able to continue from there on.

For some reason I never stumbled into that problem 3 days ago and I have not changed any files / package versions, which I can verify by my git history and also recloning my project.

Could it be that something got updated from the server-side of supabase which my cloudflare worker can not handle anymore?

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 3 months ago
  • Reactions: 12
  • Comments: 23 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Remark.

Was able to temporarily fix it by specifying the auth-js version explicitly in the package.json.

{
    "@supabase/auth-js": "^2.62.0",
    "@supabase/supabase-js": "2.39.8"
    /* other packages */
}

Edit: Sometimes only including @supabase/auth-js does not fix the issue. In that case try to add the following to your package.json: (found out by: https://github.com/cloudflare/workerd/issues/698#issuecomment-2029490141)

"overrides": {
    "@supabase/auth-js": "^2.62.0"
}

I encountered same problem on cloudflare pages hosted sveltekit app.

Seems like it was introduced with this bump of auth-js https://github.com/supabase/supabase-js/releases/tag/v2.41.1 and reason being cache:no-store not supported by cloudflare workers https://github.com/supabase/auth-js/commit/034bee09c3f0a4613d9a3e7bd3bc5f70682f5a66

actuall this release introduced another problem https://github.com/supabase/auth-js/releases/tag/v2.63.0 Now you get warnings logged for

"Using supabase.auth.getSession() is potentially insecure as it loads data directly from the storage medium (typically cookies) which may not be authentic. Prefer using supabase.auth.getUser() instead. To suppress this warning call supabase.auth.getUser() before you call supabase.auth.getSession()."

Even if you are not using getSession() anywhere because SupabaseClient itself uses it

I see getAccessToken here is using getSession https://github.dev/supabase/supabase-js/blob/6cfed0c2f958b94b0c9ff064f9e120217b6ba4ec/src/SupabaseClient.ts#L244

and its used with fetchWithAuth here https://github.dev/supabase/supabase-js/blob/6cfed0c2f958b94b0c9ff064f9e120217b6ba4ec/src/lib/fetch.ts#L35

invoked on SupabaseClient’s constructor here https://github.dev/supabase/supabase-js/blob/6cfed0c2f958b94b0c9ff064f9e120217b6ba4ec/src/SupabaseClient.ts#L103

Downgrading the version was a work around so I’m using

"@supabase/ssr": "^0.1.0"
"@supabase/supabase-js": "^2.39.7"

to solve this problem

“Error: The ‘cache’ field on ‘RequestInitializerDict’ is not implemented.”

"@supabase/ssr": "latest",
"@supabase/supabase-js": "^2.40.0",

Cloudflare, nextjs, next-on-pages

Still getting the error on “@supabase/auth-js”: “^2.64.0”

Hi @hf thanks for your helpful input!

The globals.fetch override works fine with createClient, but unfortunately not with createServerClient imported from @supabase/ssr, as @evwltrs has already mentioned.

I am using:

"@supabase/ssr": "^0.3.0",
"@supabase/supabase-js": "^2.42.4",
...
"@remix-run/cloudflare": "^2.8.1",
"@remix-run/cloudflare-pages": "^2.8.1",
"wrangler": "^3.50.0"

This is the error:

AuthRetryableFetchError: The 'cache' field on 'RequestInitializerDict' is not implemented.
      at _handleRequest2 (file:///xxx/node_modules/@supabase/auth-js/src/lib/fetch.ts:188:11)
      at async _request (file:///xxx/node_modules/@supabase/auth-js/src/lib/fetch.ts:151:16)
      at null.<anonymous> (async file:///xxx/.wrangler/tmp/dev-i7rAm1/functionsWorker-0.6340959581380707.js:42787:16)
      at async SupabaseAuthClient._useSession (file:///xxx/node_modules/@supabase/auth-js/src/GoTrueClient.ts:1053:14)
      at async SupabaseAuthClient._getUser (file:///xxx/node_modules/@supabase/auth-js/src/GoTrueClient.ts:1195:14)
      at null.<anonymous> (async file:///xxx/.wrangler/tmp/dev-i7rAm1/functionsWorker-0.6340959581380707.js:42773:58)
      at null.<anonymous> (async file:///xxx/.wrangler/tmp/dev-i7rAm1/functionsWorker-0.6340959581380707.js:42685:154) {
    __isAuthError: true,
    status: 0,
    code: undefined
  }
}

And also would appreciate some guidance on this.

I have the same issue, the latest working version for me is ^2.40.0, i think is because of bump functions-js