Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when deploying to cloudflare workers #340

Open
luizzappa opened this issue Apr 1, 2024 · 5 comments
Open

Error when deploying to cloudflare workers #340

luizzappa opened this issue Apr 1, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@luizzappa
Copy link

luizzappa commented Apr 1, 2024

Version

@nuxtjs/supabase: v1.2.0
nuxt: 3.8.1

Steps to reproduce

When using the useSupabaseUser() function on a CloudFlare Worker it returns the following error:

The 'cache' field on 'RequestInitializerDict' is not implemented

The problem started to occur in the new version v1.2.0 and from what I investigated the problem was due to an update to the supabase library as reported here. The whole problem is that the fetch used by the CloudFlare Worker does not support the cache parameter as described here.

In the case of supabase-js, the workaround is to remove the fetch cache header as described here.

However, as @nuxtjs/supabase uses the clientOptions property in nuxt.config.ts, the functions defined there do not work at run time. In other words, the code below does not work:

  supabase: {
    url: process.env.SUPABASE_URL,
    key: process.env.SUPABASE_KEY,
    serviceKey: process.env.SUPABASE_SERVICE_KEY,
    clientOptions: {
      global: {
+        fetch: (...args) => {
+          //// TEMP
+          // https://github.com/cloudflare/workerd/issues/698
+          if (args[1]?.cache) {
+            delete args[1].cache
+
+            if (!args[1]?.headers)
+              args[1].headers = {}
+
+            // @ts-ignore
+            args[1].headers['Cache-Control'] = 'no-store'
+          }
+          ////
+          return fetch(...args)
+        },
      }
    }
  },

So, this came to me with a question.. The way the library is currently implemented, how can we pass a custom fetch implementation, which is a feature of supabase-js?

@luizzappa luizzappa added the bug Something isn't working label Apr 1, 2024
@luizzappa
Copy link
Author

luizzappa commented Apr 1, 2024

For anyone facing the same problem as me, the only alternative I could find was to downgrade at package.json

    "@nuxtjs/supabase": "1.1.7"

@marcbejar
Copy link

marcbejar commented Apr 11, 2024

In my case I had the error while trying to acces to serverSupabaseUser() on a server route using Cloudflare Pages.

What finally worked for me was to downgrade the auth-js package adding this line in the package.json file: "overrides": { "@supabase/auth-js": "^2.62.0" }

If it's still not working try to delete .nuxt and node_modules and package-lock.json file. Then run npm install.

This was the way to make it work for me. Hope it helps.

@anthonyfranc
Copy link

This also causes issues with route protection on SSR, but it works fine on client only with Cloudflare pages.

"@nuxtjs/supabase": "1.1.7"

Fixed this for me also.

@vinceglb
Copy link
Contributor

Do you have any idea to work around this problem without downgrading the dependency?

@vinceglb
Copy link
Contributor

This PR seems to fix the problem: supabase/auth-js#886

They upgrade the version of @supabase/auth-js in @supabase/supabase-js supabase/supabase-js#1027 to fix supabase/supabase-js#1001

By upgrading @supabase/supabase-js v2.42.7, this should fix the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants