By Hanzalah Seikhai, payment integration developer. 3 December 2026

Stripe webhook not working in Next.js App Router: 5 causes and the fix

Next.js App Router changed how request bodies are read, and most Stripe webhook bugs in Next.js come from that. These are the checks I run.

1. Read the raw body with req.text()

Stripe signs the exact bytes it sent. Calling req.json() first and passing the parsed object breaks the signature check.

// app/api/stripe/webhook/route.ts
import Stripe from 'stripe'
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!)
export const runtime = 'nodejs'

export async function POST(req: Request) {
  const body = await req.text()
  const sig = req.headers.get('stripe-signature')!
  let event: Stripe.Event
  try {
    event = stripe.webhooks.constructEvent(body, sig, process.env.STRIPE_WEBHOOK_SECRET!)
  } catch {
    return new Response('Invalid signature', { status: 400 })
  }
  // handle event.type
  return new Response('ok')
}

2. The Edge runtime

On the Edge runtime the synchronous Node crypto that constructEvent uses is not available. Either set runtime = 'nodejs' on the route, or use constructEventAsync.

3. Middleware catches the webhook route

Auth middleware that redirects unauthenticated requests will redirect Stripe too. Exclude the webhook path in the middleware matcher.

4. Vercel Deployment Protection

If the endpoint points at a preview URL with Deployment Protection on, Stripe gets a 401 or a login page. Point Stripe at the production domain, or set up a bypass for that path.

5. Wrong secret per environment

The whsec_ secret from stripe listen only works locally. Production needs the secret of the live endpoint in the Dashboard, set in the environment variables of the production deployment, followed by a redeploy.

Then make it idempotent

Store event.id and skip events you have already handled, because Stripe retries. Update the order or the user from the webhook, not from the success page.


If you want this fixed or built in your app, see Stripe in Next.js, Node.js or Supabase, hire me on Upwork, or get in touch.

Written by Hanzalah Seikhai, Stripe developer. Hire me on Upwork.

More notes