---
title = "Unable to call Edge Function"
topics = [ "functions" ]
keywords = [ "invoke", "call", "CORS", "authentication", "JWT", "edge function" ]
---

If you're having trouble invoking an Edge Function or experiencing CORS issues, follow these steps to diagnose and resolve the problem.

## Diagnose the issue

1. **Review CORS configuration:** Check out the [CORS guide](/docs/guides/functions/cors) and ensure you've properly configured CORS headers
2. **Check function logs:** Look for errors in Functions > Logs in the dashboard
3. **Verify authentication:** Confirm JWT tokens and permissions are correct

## Proper CORS handling

Make sure your function handles OPTIONS preflight requests:

```tsx
Deno.serve(async (req) => {
  // Handle CORS preflight requests
  if (req.method === 'OPTIONS') {
    return new Response(null, {
      status: 200,
      headers: {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
        'Access-Control-Allow-Headers': 'Content-Type, Authorization',
      },
    })
  }

  // Your function logic here
  return new Response('Success', {
    headers: { 'Access-Control-Allow-Origin': '*' },
  })
})
```

## Debugging tools

Supabase provides two debugging tools for Edge Functions:

- **Invocations:** Shows the Request and Response for each execution
- **Logs:** Shows platform events, including deployments and errors

Access these tools by navigating to Functions > [Your Function] in the dashboard.

## Common issues

### CORS errors

- Missing `Access-Control-Allow-Origin` header in response
- Not handling OPTIONS preflight requests
- Mismatched allowed methods or headers

### Authentication errors

- Invalid or expired JWT token
- Missing Authorization header
- Incorrect permissions for the authenticated user

### Network errors

- Function not deployed
- Incorrect function URL
- Network connectivity issues

## Additional resources

- [CORS guide](/docs/guides/functions/cors)
- [Edge Functions authentication](/docs/guides/functions/auth)
- [Debugging Edge Functions](/docs/guides/functions/logging)
