Fixes › Database / Supabase RLS
Supabase Edge Function fails with CORS or 'Failed to send a request'
The error
FunctionsFetchError: Failed to send a request to the Edge Function / CORS preflight failed
Why it happens
The Edge Function doesn't answer the OPTIONS preflight with CORS headers, or it throws before returning headers. A missing secret (Deno.env.get returns undefined) commonly causes that crash.
How to fix it
- Handle OPTIONS first: if (req.method === 'OPTIONS') return new Response('ok', { headers: corsHeaders })
- Include corsHeaders on every response, errors included.
- Set secrets with supabase secrets set NAME=value (or the Dashboard → Edge Functions → Secrets).
- Check the function logs in the Supabase dashboard.
Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)
Calling my Supabase Edge Function <NAME> fails with a CORS or 'Failed to send a request' error. Add a corsHeaders object, return early for OPTIONS requests, include the headers on every response including errors, wrap the body in try/catch returning JSON errors, and list which secrets the function reads so I can set them in Supabase.
FAQ
Where are the logs?
Supabase Dashboard → Edge Functions → the function → Logs.
Does it need my anon key?
supabase.functions.invoke sends it automatically.
Related fixes
- Supabase query returns an empty array (no error)
- new row violates row-level security policy for table
- Supabase Storage upload fails: new row violates row-level security policy (403)
- Postgres error: relation "public.xyz" does not exist
Want the full checklist for this area? Get a Fix Kit ($29)
Featured slot available: reach thousands of vibe coders. Sponsor this week →
Get one new fix a week
Free newsletter: the newest breakages in Lovable, Bolt, Cursor, Replit and v0 apps, with paste-in fixes.
We only use your email to send the newsletter. Unsubscribe any time. See privacy.