Supabase Edge Function blocked by CORS policy
Last verified: October 18, 2026
Access to fetch at 'https://<project>.supabase.co/functions/v1/...' has been blocked by CORS policy: Response to preflight request doesn't pass access control check
What it means
Browsers send an OPTIONS “preflight” request before calling your Edge Function. If the function doesn't answer it, or its responses (including error responses) don't include CORS headers allowing authorization, apikey, x-client-info and content-type, the browser blocks the call. A crash inside the function can show up as a CORS error too, because the error response has no CORS headers.
How to fix it
- Open Edge Functions → your function → Logs to see whether the request reached it and if it crashed.
- At the top of the function, return early for
OPTIONSrequests with the CORS headers. - Add the same CORS headers to every response, including errors. With supabase-js v2.95.0+ you can import
corsHeadersfromnpm:@supabase/supabase-js@^2/cors. - Redeploy the function and call it again from the app.
If your Lovable project uses Lovable Cloud instead of your own Supabase project, the same database lives under More → Cloud → Database. Its RLS view is read-only, so ask Lovable in chat (Plan mode) to make the policy change.
Stop the loop: paste these into Lovable
1. Diagnose first
Stop editing and don't retry earlier fixes. Calling my Supabase Edge Function from the browser fails with: blocked by CORS policy: Response to preflight request doesn't pass access control check. Without changing anything, show me the function's code: does it handle OPTIONS, which headers it returns on success and on errors, and check the function logs for a crash. State the cause in one sentence and propose ONE minimal change.
2. Then the one fix
In this one Edge Function only: handle the OPTIONS preflight first and return the CORS headers, and include the same headers on every response including errors (import corsHeaders from npm:@supabase/supabase-js@^2/cors, or define Access-Control-Allow-Origin and Access-Control-Allow-Headers: authorization, x-client-info, apikey, content-type). Wrap the body in try/catch so crashes still return JSON with CORS headers. Don't change the function's logic or secrets. Redeploy, test from the app, and tell me exactly what changed.
3. Save this rule so it stays fixed
Lovable: Project settings → Knowledge. Cursor: .cursor/rules or .cursorrules. Bolt: Project settings → Knowledge. Replit: replit.md.
Rule: Every Supabase Edge Function called from the browser handles OPTIONS first and returns the shared corsHeaders on every response, including errors (wrap the handler in try/catch). Call functions with supabase.functions.invoke and keep API secrets in Edge Function secrets, never in client code.
FAQ
The function works in curl but not the app. Why?
curl doesn't do CORS preflights. Browsers do, so only browser calls fail.
Should I set Access-Control-Allow-Origin to my domain instead of *?
You can. It's stricter. Just make sure every domain that calls the function (preview and live) is allowed.
Sources
Your error is a bit different? Paste it with what you already tried and get a diagnose-first prompt, one fix and a rule for your exact case.
Break the loop — 3 free fixes Still stuck? Get a human fix