Guide
Supabase Edge Function 401 Invalid JWT or Missing authorization header
How this guide was made: Written with AI assistance and checked against the sources linked on this page.
Updated
Short answer: a 401 "Invalid JWT" from a Supabase Edge Function usually comes from the built-in JWT check, which runs before your code. Check the response body first. If your project uses the new API keys, Supabase recommends turning that check off (--no-verify-jwt) and verifying the user inside the function. Otherwise, send the signed-in user's access token.
Why it happens
Every request to an Edge Function passes through a platform-level check before your code executes. When that check is on and the Authorization header is missing, malformed, or signed with a different key, the platform returns a 401 and your code never runs. A 401 can also be returned by your own function code, in which case the function did run.
Possible causes
- The built-in JWT check is on and the key sent does not match your project's keys.
- Your project uses the new asymmetric keys, but the legacy check only understands the legacy format.
- The request has no Authorization header at all, which the check rejects when it is on.
- A credential was sent in the wrong header: user tokens belong in Authorization and API keys belong in apikey.
- Your own function code ran and returned a 401 itself, for example from a third-party API response.
Official fix steps
- Check the response body: "Invalid Token or Protected Header formatting", "Invalid JWT" or "Missing authorization header" means the built-in check failed. (supabase.com)
- If the body has a message you coded or is empty, your function ran and returned the 401 itself. (supabase.com)
- In the Functions Dashboard, open the affected function's detail tab and toggle off JWT verification. (supabase.com)
- Or redeploy the function from the Supabase CLI with the no-verify-jwt flag. (supabase.com)
- Know that turning the check off removes the platform's check, so the verification inside your own function is then the only thing that verifies the caller. (supabase.com)
- If you keep the check on, send a valid legacy API key with the Supabase client library. (supabase.com)
- Put API keys in the apikey header and reserve Authorization for user tokens. (supabase.com)
You can't see it yourself
You're signed in, your customers aren't. While you are signed in, your requests carry your session token. With the check on, the platform expects a valid user JWT in the Authorization header, and if it is missing, malformed, or signed with a different key, the platform returns a 401 before your code runs. That means a caller without a valid token can get a result you never see yourself.
What to do next
App broke after you published it? Our AI agent fixes it in your code, then tests your live app again so you see the result yourself. The first check is free.
Related: Supabase legacy API keys are going away: will your app break? · Supabase "permission denied for table" (42501) fix
Auth error: {401: invalid claim: missing sub}
Supabase's page with this title says the error appears when supabase.auth.getUser() is called with an invalid JWT, or when a Supabase API key is passed where the user's Auth access token belongs. API keys have no sub claim, which is the field that holds the user ID, so the check fails.
- Find the token your function passes to
supabase.auth.getUser(). - Make sure it is the signed-in user's Auth access token, not the publishable or secret API key.
- In the client, send the user's access token to the function in the
Authorization: Bearerheader. - In the function, read that header and pass the token to
supabase.auth.getUser(token). - If you create the Supabase client for each request, check how it is initialised on the server.
- Redeploy the function, sign in, and call it again.
Sources
Last checked: 10 November 2026, against the sources listed above.
VibeFix is independent. Lovable, Bolt, Replit, Base44, v0 and Supabase are trademarks of their owners. - Supabase: Auth error 401 invalid claim missing sub
Want it fixed?
Our AI agent fixes it in your code for $79 and tests your live app again. If we can't complete your re-check, you get your money back.
It starts with a free check that confirms the problem on your live app, no account needed.
More guides · Shopify store accessibility · About · Your privacy choices