Stripe webhook not working in a Supabase Edge Function: 401s, signature errors and missing upgrades

By AI App Medic · Updated · Stripe · Supabase · Payments

The classic symptom: Stripe shows the payment as succeeded, but the user is still on the free plan. In Lovable and Bolt apps the webhook usually lives in a Supabase Edge Function, and it fails for one of a few predictable reasons. Start in Stripe: Developers > Webhooks > your endpoint > event deliveries shows the HTTP status your function returned for each event.

Status 401: JWT verification is blocking Stripe

Edge Functions require a valid Supabase JWT by default. Stripe cannot send one, so Supabase rejects the call before your code runs. Turn verification off for this one function and rely on Stripe's signature check instead:

supabase functions deploy stripe-webhook --no-verify-jwt

Or in supabase/config.toml:

[functions.stripe-webhook]
verify_jwt = false

Status 400: signature verification fails

Verify against the raw body and use the async verifier, because Edge Functions run on Deno with Web Crypto:

import Stripe from 'npm:stripe';

const stripe = new Stripe(Deno.env.get('STRIPE_SECRET_KEY')!);
const cryptoProvider = Stripe.createSubtleCryptoProvider();

Deno.serve(async (req) => {
  const signature = req.headers.get('Stripe-Signature');
  const body = await req.text(); // raw text, not req.json()
  let event;
  try {
    event = await stripe.webhooks.constructEventAsync(
      body, signature!, Deno.env.get('STRIPE_WEBHOOK_SECRET')!, undefined, cryptoProvider
    );
  } catch (err) {
    return new Response(`Webhook signature error: ${err.message}`, { status: 400 });
  }
  // handle event.type here
  return new Response(JSON.stringify({ received: true }), { status: 200 });
});

If verification still fails, check the secret:

Status 200 but nobody gets upgraded

A few extra checks

FAQ

Why does my Stripe webhook get a 401 from Supabase?

Supabase Edge Functions verify a Supabase JWT by default. Stripe does not send one, so the request is rejected before your code runs. Deploy the webhook function with JWT verification turned off and verify Stripe's signature instead.

What causes 'No signatures found matching the expected signature for payload'?

Usually the wrong webhook secret (test vs live, or the Stripe CLI secret in production), or the body was parsed and re-serialized before verification. Verify against the raw request text.

How do I know which user paid?

Pass your user id when creating the Checkout Session (client_reference_id or metadata), or match on the customer email. Then read it from the checkout.session.completed event.

Related guides