Guides

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

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

  1. Find the function's name: it's the last part of the webhook address in Stripe, for example stripe-webhook.
  2. Turn off the login check for that function only. In supabase/config.toml add:
    [functions.stripe-webhook]
    verify_jwt = false
    Or deploy it with supabase functions deploy stripe-webhook --no-verify-jwt. Leave every other function as it was.
  3. Make sure the function verifies Stripe's signature before doing anything (next section). This is what keeps it safe now that it's public.
  4. Set the signing secret as an Edge Function secret, for example STRIPE_WEBHOOK_SIGNING_SECRET, using the whsec_ value from that exact endpoint in Stripe. Test mode and live mode endpoints each have their own.
  5. Redeploy the function, then in Stripe resend a failed event from the endpoint's event deliveries and check it now shows 200.
  6. 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:

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 check

Settings 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