🔧 Unbreak My AppAll fixesFix KitsSponsor

Fixes › Database / Supabase RLS

Supabase Edge Function fails with CORS or 'Failed to send a request'

LovableBolt

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

  1. Handle OPTIONS first: if (req.method === 'OPTIONS') return new Response('ok', { headers: corsHeaders })
  2. Include corsHeaders on every response, errors included.
  3. Set secrets with supabase secrets set NAME=value (or the Dashboard → Edge Functions → Secrets).
  4. 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

Want the full checklist for this area? Get a Fix Kit ($29)

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.