Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

fix: strip unsupported cache field from Supabase fetch calls in Workers

valzorc446a7f0559d
diff --git a/backend/lib/supabase.js b/backend/lib/supabase.js
index 0ccb253..4bdbcec 100644
--- a/backend/lib/supabase.js
+++ b/backend/lib/supabase.js
@@ -4,12 +4,21 @@ function clean(s) {
return s?.replace(/^/, '').trim();
}
+// Cloudflare Workers does not support the `cache` field on RequestInit.
+// Strip it from all fetch calls made by the Supabase client.
+function workerFetch(url, options = {}) {
+ const { cache, ...rest } = options;
+ return fetch(url, rest);
+}
+
+const CLIENT_OPTS = { auth: { persistSession: false }, global: { fetch: workerFetch } };
+
// Returns a service-role client that bypasses RLS - used for all DB operations.
export function getSupabase(env) {
- return createClient(clean(env.SUPABASE_URL), clean(env.SUPABASE_SERVICE_KEY), { auth: { persistSession: false } });
+ return createClient(clean(env.SUPABASE_URL), clean(env.SUPABASE_SERVICE_KEY), CLIENT_OPTS);
}
// Returns an anon client - used only to verify user JWTs in auth middleware.
export function getSupabaseAuth(env) {
- return createClient(clean(env.SUPABASE_URL), clean(env.SUPABASE_ANON_KEY), { auth: { persistSession: false } });
+ return createClient(clean(env.SUPABASE_URL), clean(env.SUPABASE_ANON_KEY), CLIENT_OPTS);
}