Error library

Symptom: CORS error calling Supabase Edge Function

The browser blocked the call because the function didn't answer the OPTIONS preflight or return CORS headers. Use Supabase's withSupabase wrapper, which handles CORS and preflight for you, or handle OPTIONS yourself and add CORS headers to every response, including errors.

Get this exact error fixed — $49 Quick FixFixed within scope, or we keep working until it is · Read-only access Not sure it's this error? $149 diagnosis

Cause: The function doesn't answer the preflight or omits Access-Control-Allow-Origin / allowed headers.

How to fix it

  1. If available in your setup, wrap the handler with withSupabase (per Supabase's CORS guide) so CORS is handled automatically.
  2. Otherwise, return early for OPTIONS requests with the CORS headers.
  3. Include the CORS headers on every response, including error responses.
  4. Allow the headers supabase-js sends (authorization, x-client-info, apikey, content-type).
  5. Restrict the allowed origin to your domain in production.

Example

Illustrative example, not from a customer project.

+ if (req.method === 'OPTIONS') return new Response('ok', { headers: corsHeaders })
- return new Response(JSON.stringify(data))
+ return new Response(JSON.stringify(data), { headers: { ...corsHeaders, 'Content-Type': 'application/json' } })

FAQ

Why does it work with curl?

CORS is enforced only by browsers.

Do errors need CORS headers too?

Yes, otherwise the browser hides the real error behind a CORS message.

QUICK FIX · $49 · THIS ERROR ONLY

Get this exact error fixed — $49 Quick FixFixed within scope, or we keep working until it is · Read-only access Not sure it's this error? $149 diagnosis

One error, one root cause, fixed in your app. If it turns out bigger, we tell you before doing more, and your $49 is credited toward the fix, diagnosis or Launch Path if you book within 14 days. Fixing three? The 3-Error Pack is $119.

Bigger job: More than one auth or data issue? Auth & database security fix, from $400.

Built with Lovable, Bolt, Replit, Cursor or v0? See rescue by platform and the security checklist.

Check it yourself first, free

$49Fix this error