I'm having CORS issues when upgrading functions to use Supabase v2.0.0

Since Supabase JS is now available in v2 I'm trying to modify my edge function to use this new version but I'm having CORS issues when I remove JSON.stringify() from the body when invoking the function.

Invoke before
await supabaseClient.functions.invoke("media-upload", {
  body: JSON.stringify({
    path: fileName,
  }),
});

Invoke after
await supabaseClient.functions.invoke("media-upload", {
  body: {
    path: fileName,
  },
});


In my function:
const corsHeaders = {
  "Access-Control-Allow-Origin": "*",
  "Access-Control-Allow-Headers": "authorization, x-client-info, apikey",
};

serve(async (req) => {
  if (req.method === "OPTIONS") {
    return new Response("ok", { headers: corsHeaders });
  }

  try {
    ...
  } catch (error) {
    ...
  }
});


Any idea why if I remove JSON.stringify() I get a CORS error? It seems that now we have to remove it with v2.
Was this page helpful?