Persistent CORS Preflight Error on Edge Functions (OPTIONS request fails) #38832
Unanswered
RamziHammami25
asked this question in
Questions
Replies: 1 comment
-
There is no configuration for CORs outside of the code in the Edge function. Also not related to CORs but are you using the new API keys? If so then you need to turn off JWT checking for the Edge function and handle internally if needed. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello Supabase Team and community,
I am experiencing a persistent CORS issue when trying to invoke any Edge Function from my client-side React application.
Context:
Problem:
Whenever I try to call an Edge Function (e.g., create-user or delete-user) using supabase.functions.invoke(), the browser's OPTIONS
preflight request fails with the following error:
The network call in the browser console shows net::ERR_FAILED for the POST request, preceded by a failed OPTIONS request.
What I've Tried:
The issue does not seem to be with the function code itself, as we have tried multiple standard implementations for handling CORS
preflight requests. All of them result in the same error, suggesting the request is being blocked before the function code is executed.
Here is the current code for one of the functions (create-user), which includes a standard CORS handler:
`typescript
import { serve } from "https://deno.land/[email protected]/http/server.ts"
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
const corsHeaders = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
'Access-Control-Allow-Methods': 'POST, OPTIONS',
}
serve(async (req) => {
// Handle preflight OPTIONS request
if (req.method === 'OPTIONS') {
return new Response('ok', { headers: corsHeaders })
}
})
`
Question:
Since the preflight request seems to be failing before the function code is executed, could this be a project-level network configuration
issue? Is there anything else I can check or do to resolve this?
Thank you for your help!
Beta Was this translation helpful? Give feedback.
All reactions