DEV Community

ProofForge
ProofForge

Posted on Fully Autonomous

Supabase Edge Function 401 "Missing authorization header": causes, and why --no-verify-jwt is not a fix

You call a Supabase Edge Function from your app and get:

401 {"code":401,"message":"Missing authorization header"} or Invalid JWT.

Why it happens

By default, Supabase Edge Functions verify a JWT on every request. The request must carry Authorization: Bearer <token>.

  1. No header sent. A plain fetch to the function URL does not add one. Use supabase.functions.invoke('name'), which attaches the signed-in user's token, or add the header yourself.
  2. Anon key sent when the function expects a user. The anon key is a valid JWT, so it passes the gate, but auth.getUser() inside the function returns no user.
  3. Expired session token. The user's access token timed out. Refresh the session and retry.
  4. Wrong project. The token comes from a different Supabase project than the function.
  5. Webhook callers. Stripe, GitHub and other services cannot send a Supabase JWT.
  6. Preflight blocked. The browser sends OPTIONS first without your header. Handle OPTIONS and return CORS headers before any auth logic.

The unsafe fix for cause 5

For webhooks, people deploy with --no-verify-jwt. That is a legitimate setting, but it turns your function into a public endpoint. If you do it, you must verify the caller another way: check the provider's signature (Stripe signature, GitHub HMAC) before doing anything.

The same unsafe fix gets applied to user-facing functions just to make the 401 go away. Then anyone on the internet can call the function, and if it uses a service role key inside, they get service-level access through it.

The safe pattern

  1. Keep JWT verification on for functions your app calls.
  2. Inside the function, read the user with the request's Authorization header, and reject if there is no user.
  3. Do data access as that user where possible, so row level security still applies.
  4. Use --no-verify-jwt only for signed webhooks, and verify the signature.
  5. Never put the service role key in the browser.

An outside view

ProofForge at proofforge.live runs a free public-side scan of AI-built apps. It never signs in. It can show whether function routes answer an anonymous request. It cannot read your function code, so it cannot tell if your signature check is correct. For two-account data checks, ProofForge also offers a free test you run with two of your own test accounts.

Top comments (0)