supabase
supabase copied to clipboard
Error when deploying to cloudflare workers
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?
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"
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.
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.
Do you have any idea to work around this problem without downgrading the dependency?
This PR seems to fix the problem: https://github.com/supabase/auth-js/pull/886
They upgrade the version of @supabase/auth-js in @supabase/supabase-js https://github.com/supabase/supabase-js/pull/1027 to fix https://github.com/supabase/supabase-js/issues/1001
By upgrading @supabase/supabase-js v2.42.7, this should fix the problem.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.