shipfix

Common errors · Supabase Edge Functions called from Lovable, Bolt, any browser app

Supabase Edge Function: blocked by CORS policy

Cause The function does not answer the OPTIONS preflight, or its error responses carry no CORS headers.
Fix Answer OPTIONS, add the CORS headers to every response including errors, then read the function logs for the real error.

Access to fetch at 'https://xyz.supabase.co/functions/v1/...' has been blocked by CORS policy: Response to preflight request doesn't pass access control check

Have it fixed for you, 290 EURSee the fix step by step

What you receive a diff on a branch of your repository, and a correction note: root cause, change made, how to verify it. See a sample report

The function works with curl and fails from the browser. Browsers send an OPTIONS preflight first, and the function either crashes on it or answers without the CORS headers.

Where it breaks

BrowserOPTIONS preflightEdge Functionno OPTIONS branchNo CORS headerson error responsesBlockedreal error hiddenfirst500 or404browserstopsBrowserOPTIONS preflightEdge Functionno OPTIONS branchNo CORS headerson error responsesBlockedreal error hiddenfirst500 or 404browser stops
The browser sends OPTIONS first. If the function does not answer it, or an error response lacks the headers, the real call is blocked.

Which case is yours?

  1. The function does not handle the OPTIONS method, or returns headers only on success. An error response without CORS headers also shows up as a CORS error, hiding the real exception.

The fix, step by step

  1. Answer the preflight and add the headers to every response, errors included.
    const cors = {
      "Access-Control-Allow-Origin": "https://app.example.com",
      "Access-Control-Allow-Headers": "authorization, x-client-info, apikey, content-type",
    };
    Deno.serve(async (req) => {
      if (req.method === "OPTIONS") return new Response("ok", { headers: cors });
      try {
        // ... your code
        return new Response(JSON.stringify(data), { headers: { ...cors, "Content-Type": "application/json" } });
      } catch (e) {
        return new Response(JSON.stringify({ error: String(e) }), { status: 500, headers: cors });
      }
    });
  2. Call it with supabase.functions.invoke so the auth and apikey headers are set for you.
  3. Then read the function logs in the dashboard: once CORS is fixed, the real error (missing secret, bad JSON) becomes visible.

How to check it is fixed

The Network tab shows OPTIONS 200 then POST 200 (or a readable 4xx/5xx with a JSON body), and no CORS line in the console.

Delivery example for this error

functions/api/index.ts · on a branch of your repository- return new Response(json)+ if (req.method === "OPTIONS")+ return new Response("ok", { headers: cors })
Verification checklist in the note
  • Root cause: The function does not answer the OPTIONS preflight, or its error responses carry no CORS headers.
  • Change made: Answer OPTIONS, add the CORS headers to every response including errors, then read the function logs for the real error.
  • The Network tab shows OPTIONS 200 then POST 200 (or a readable 4xx/5xx with a JSON body), and no CORS line in the console.

Illustrative: the real diff is written against your repository. Full sample report

Still stuck on your own code?

Send the repository and the exact error. Fix: 290 EUR all taxes included, delivered within 72 hours, refunded if not resolved.

Private repository: paste its link anyway, we reply by email within one business day with the GitHub account to invite with read access. A zip link (Google Drive, Dropbox) works too. Never send passwords or secret keys in this form.

Fix: One blocking auth, Supabase RLS or deployment problem fixed in your repository.290 EUR all taxes included · 72 hours

Secure payment by Stripe. Not resolved within 72 hours: refunded in full.

Not sure it is this error? Ask for a free written diagnosis, no card needed.