Stripe webhook fails with 401 on a Supabase Edge Function
Short answer: Supabase Edge Functions require a logged-in user's token by default, and Stripe doesn't have one, so Supabase answers 401 before your code even runs. Turn off that check for the webhook function only (verify_jwt = false in supabase/config.toml, or --no-verify-jwt when you deploy), then make sure your function checks the Stripe-Signature header with your whsec_ secret. Without that signature check, anyone could call it.
Signs this is your problem
- A customer paid, Stripe shows the payment, but your app never marked them as paid or unlocked anything.
- In Stripe's dashboard, your webhook endpoint's event deliveries show Failed with status
401. - The webhook address looks like
https://<project>.supabase.co/functions/v1/stripe-webhook. - Your function's own logs show nothing for those payments, because the request never reached your code.
Why it happens
By default, every Supabase Edge Function expects a valid JWT (a signed login token) in the Authorization header. Your app's Supabase client adds it for you when a logged-in user calls a function, so everything works while you test from the app.
Stripe is a different caller. It sends payment events straight from its servers, with no user and no Supabase token. Supabase's docs say it plainly: Stripe webhooks need to be publicly accessible because Stripe doesn't have your user tokens. So the platform rejects the request with 401 and Stripe records a failed delivery. Stripe's docs list 401 and 403 as signs that the address has access restrictions.
Fix it, step by step
- Find the function's name: it's the last part of the webhook address in Stripe, for example
stripe-webhook. - Turn off the login check for that function only. In
supabase/config.tomladd:
Or deploy it with[functions.stripe-webhook] verify_jwt = falsesupabase functions deploy stripe-webhook --no-verify-jwt. Leave every other function as it was. - Make sure the function verifies Stripe's signature before doing anything (next section). This is what keeps it safe now that it's public.
- Set the signing secret as an Edge Function secret, for example
STRIPE_WEBHOOK_SIGNING_SECRET, using thewhsec_value from that exact endpoint in Stripe. Test mode and live mode endpoints each have their own. - Redeploy the function, then in Stripe resend a failed event from the endpoint's event deliveries and check it now shows
200. - Stripe retries undelivered events for up to three days. For older payments that failed, check those customers by hand or reprocess the missed events, and make sure your code skips an event it has already handled.
The signature check is not optional
Supabase warns that turning off the JWT check lets anyone call the function. That's fine only because Stripe signs every event. Your function should:
- Read the raw body with
await req.text(), notreq.json(). Stripe's signature is over the exact text it sent, so a parsed and re-encoded body fails the check. - Verify it with
stripe.webhooks.constructEventAsync(body, signature, secret, undefined, cryptoProvider), wherecryptoProvidercomes fromStripe.createSubtleCryptoProvider(). Supabase's own Stripe example uses this async version because Edge Functions run on Deno and use the Web Crypto API. - Return an error (Supabase's example uses
400) when the check fails, and only unlock, upgrade or email anyone after it passes. - Answer Stripe quickly with a
2xx, and do slow work after that or in the background, so Stripe doesn't time out and retry.
If you see "No signatures found matching the expected signature for payload", Stripe says the usual cause is the wrong secret, for example a stripe listen secret from your computer instead of the dashboard endpoint's secret.
Built with Lovable, Bolt, Cursor, or by hand?
You can paste this to your AI builder:
Stripe webhook deliveries to my Supabase Edge Function fail with 401. Please:
1. Set verify_jwt = false for the webhook function only, in supabase/config.toml (leave other functions unchanged).
2. Make sure the function reads the raw body with req.text() and verifies the Stripe-Signature header with stripe.webhooks.constructEventAsync and Stripe.createSubtleCryptoProvider(), using a secret from Deno.env.
3. Return an error if verification fails and do nothing else in that case.
4. Skip events whose id was already processed.
Do not print or hardcode any secret values.
Then set the whsec_ secret yourself in Supabase, redeploy, and resend a test event from Stripe.
How AppFirstAid helps
When our free check sees Stripe in your live site's code, it opens the webhook addresses it can find, including Supabase Edge Function addresses whose names mention Stripe or webhooks, with a plain GET request. We never send a fake payment event. If the address answers with a login wall instead of a signature error, the report flags that Stripe may be stuck at a login. A webhook that rejects unsigned requests is correct, and we don't flag that. A journey test goes further on your live site: a real browser signs up, logs in and tries checkout, and shows you the step that broke. If payments go through but nothing unlocks for other reasons, read Stripe says they paid, but nothing unlocked, and for test versus live keys, My app works in preview but breaks in production.
Common questions
Why does my Stripe webhook get 401 from a Supabase Edge Function?
Supabase Edge Functions expect a valid JWT (a login token) by default. Stripe calls from its own servers with no user token, so Supabase answers 401 before your code runs.
How do I turn off the JWT check for just the webhook function?
Add [functions.stripe-webhook] with verify_jwt = false to supabase/config.toml (use your function's name), or deploy it with supabase functions deploy stripe-webhook --no-verify-jwt. Leave every other function as it was.
Is it safe to make the webhook function public?
Only if it verifies Stripe's signature first: read the raw body with req.text(), check the Stripe-Signature header with constructEventAsync and your whsec_ secret, and return an error without doing anything when the check fails.
What does "No signatures found matching the expected signature for payload" mean?
Stripe says the usual cause is the wrong signing secret, for example a stripe listen secret from your computer instead of the dashboard endpoint's whsec_ secret. Test and live endpoints each have their own.
Sources, read October 28, 2026: Supabase docs "Function Configuration" (JWT required by default, Stripe webhooks need to be public, verify_jwt = false, --no-verify-jwt, the caution that anyone can then call it); Supabase's "Handling Stripe Webhooks" example (raw body via req.text(), constructEventAsync with createSubtleCryptoProvider); Stripe docs "Manage webhook endpoints" (401/403 mean access restrictions, wrong-secret signature errors, retries for up to three days, quick 2xx, duplicate events). These tools may change these details.
Check your live app in under a minute
AppFirstAid's free check looks at your live site from the outside: leaked keys, files left in public, safety settings, and whether your sign-up, login and checkout pages open. No signup. Journey tests go further: a simulated first-time user (a real browser) signs up, opens your email, logs in and tries checkout, and shows you the step that broke. Your first journey test is free.
Run the free checkSettings move around as these tools update. If a menu name has changed, look for the same words nearby. Spotted something out of date? Tell us.
More guides
- Stripe says they paid, but nothing unlocked in my vibe-coded app
- Login broke after I added my custom domain (Supabase redirect URLs)
- What built-in security scans miss in AI-built apps
- Supabase confirmation emails not arriving for new users
- Supabase "permission denied for table" (error 42501) on a new table: why it happens and the fix
- My app works in preview but breaks in production (environment variables differ)
- Error 400: redirect_uri_mismatch on Google sign-in (or "The JavaScript origin in the request does not match")
- Lovable app launch checklist: how to test your Lovable app before launch (sign-up, email, login, checkout)
- Bolt app shows a database permissions error on a new table (tables private by default since Oct 30, 2026)