Fix guide · updated 2026-11-15
Supabase Edge Function "Missing authorization header" (401)
401 · {"code":"unauthorized_no_auth_header","message":"Missing authorization header"}
Your Edge Function answers 401 with "Missing authorization header", and the function's logs show nothing from your code. That's because your code never ran: Supabase checks every request before your function starts, and this one arrived without the header that check expects. Here's who sends that header, who doesn't, and the two safe ways to fix it.
What the error means
Edge Functions have a check in front of your code called verify_jwt, on by default. It reads the Authorization header of every request. If there's none, the platform answers 401 and your function never starts (Supabase's docs, "Edge Function 401 error response"). The body is {"code":"unauthorized_no_auth_header","message":"Missing authorization header"}; Supabase's own docs also show an older shape, {"code":401,"message":"Missing authorization header"}.
Supabase's client adds the header for you: supabase.functions.invoke sends the signed-in user's token, or your project's key when nobody is signed in. So this error almost always comes from a caller that isn't your app's Supabase client.
1. A webhook or another service calls the function
Stripe, GitHub, Resend, a cron service, Zapier: none of them know about your Supabase login, so their requests arrive with no Authorization header and stop at the check. For these functions, turn the check off, and check the caller yourself in your code instead (for Stripe, the webhook signature; for others, a secret header only they know).
Three ways to turn it off for one function:
- Dashboard: Edge Functions → open the function → its details → turn off JWT verification.
- CLI:
supabase functions deploy stripe-webhook --no-verify-jwt - In your code: in
supabase/config.toml, so every deploy uses it:
[functions.stripe-webhook]
verify_jwt = false
Our guide on Stripe webhooks in a Supabase Edge Function shows the signature check that has to replace it.
2. Your own code calls the function with fetch
If your frontend calls https://<project>.supabase.co/functions/v1/<name> with plain fetch or axios, nothing adds the header. Use the Supabase client instead, which adds it:
const { data, error } = await supabase.functions.invoke('my-function', {
body: { name: 'Ada' },
});
Never put your service role key or secret key in browser code to get past the check. Anyone can read it there, and it bypasses every security rule in your database.
3. "Invalid JWT" comes right after
Same check, other message: the header is there, but what's in it can't be verified. Usually it's an expired token (why the browser sent one: Supabase "JWT expired"), a token from another Supabase project, or a project that moved to Supabase's new signing keys, which the old check doesn't understand ("Invalid Token or Protected Header formatting"). Supabase's own advice is to turn the built-in check off and verify the user in your function's code.
Turning the check off: what you take on
With verify_jwt off, anyone who finds the URL can call the function. That's fine when the code checks the caller: a Stripe signature, a secret header, or the user's token. For a function your signed-in users call, check the token at the top:
import { createClient } from 'npm:@supabase/supabase-js@2';
Deno.serve(async (req) => {
const supabase = createClient(Deno.env.get('SUPABASE_URL')!, Deno.env.get('SUPABASE_ANON_KEY')!, {
global: { headers: { Authorization: req.headers.get('Authorization') ?? '' } },
});
const { data: { user } } = await supabase.auth.getUser();
if (!user) return new Response('Unauthorized', { status: 401 });
// the rest of your function, for this user
});
Don't turn the check off on a function that reads or writes user data without a check like this one.
Find out which 401 you have
- "Missing authorization header", "Invalid JWT" or "Invalid Token…": the check stopped the request. Your code didn't run, so it logged nothing.
- Any other body, or an empty one: your own code ran and returned 401. Search your function for
401, or for a third-party API whose 401 you pass along.
Supabase's knowledge base article "Edge Function 401 error response" has a SQL query for your logs that sorts recent 401s by cause.
If an AI tool built your app
Give your AI tool this prompt:
Find every place in the frontend that calls a Supabase Edge Function with fetch or axios, and replace it with supabase.functions.invoke('<function name>', { body }), so the user's session token is sent. Don't put any service role or secret key in frontend code. List the Edge Functions that are called by outside services (webhooks such as Stripe), and don't change those callers. Don't change anything else.
Then, for each webhook function on that list, turn off JWT verification yourself (case 1) and make sure the function checks the caller's signature or secret.
Not quite your error?
- The app only says "Edge Function returned a non-2xx status code": read the real error behind it.
- The browser's console says "has been blocked by CORS policy": Supabase Edge Function "blocked by CORS policy".
- Stripe shows 400 or 401 on your webhook: Stripe webhook errors with a Supabase Edge Function.
- The database refuses the function's query: Supabase "permission denied for table" (42501).
Still stuck?
Call the function from a terminal with the header set, using your project's anon or publishable key, and compare: curl -X POST 'https://<project>.supabase.co/functions/v1/<name>' -H 'Authorization: Bearer <key>' --data '{}'. If that works and your app still gets 401, your app isn't sending the header: open the browser's Network tab and look at the request's headers.
Other Supabase problems? See Supabase fixes.