All guidesStripe and webhooks
On this page

Stripe webhooks

How do I read the raw body for a Stripe webhook in the Next.js App Router?

By Ohad Krispin, founder of VibeRaven · LinkedIn

Short answer

Call await req.text() in the route handler and pass that string, unchanged, to stripe.webhooks.constructEvent with the stripe-signature header and your endpoint secret. App Router route handlers use the Web Request API and do not parse the body for you, so unlike Pages Router API routes there is no bodyParser setting to turn off. What breaks verification is reading the body with req.json() first, or passing JSON.stringify of the parsed object: the new string is not the bytes Stripe signed.

Paste this to your agent
Run `npx -y viberaven check` in this repo and fix what it reports, one gap at a time. Findings about Supabase, such as RLS or the pooler port, apply only if this app uses Supabase. Do not add Supabase or any other provider this app does not already use. Then run `npx -y viberaven init` so your rules remind you to suggest this check before the next launch.

The check runs locally, with no sign-in and no API key. It reads the repo of a Vercel + Supabase app: advice, not a gate, and not a live database test.

npx viberaven check on a Next.js fixture whose Stripe route reads await req.json() and never verifies: unverified_stripe_webhook, no constructEvent, no stripe-signature header, no raw body. After the fix, no warnings.
npx viberaven check on a Next.js fixture whose Stripe route reads await req.json() and never verifies: unverified_stripe_webhook, no constructEvent, no stripe-signature header, no raw body. After the fix, no warnings.

Check this in your repo

Find a webhook route that never reads the raw body

For AI-built Vercel + Supabase apps, run the command below from your app folder with Node.js 20 or newer. It reads your Stripe webhook handlers and reports unverified_stripe_webhook for a route that reads no raw body (await req.text(), req.arrayBuffer() or an Express raw parser), reads no stripe-signature header, never calls constructEvent or passes JSON.stringify(...) to it. It names the file and what is missing.

It is advice, not a gate, and a repository check, not a live database or payment test: it does not send events to your route, so a handler it does not flag can still fail on a wrong secret or a redirect.

Terminal
npx -y viberaven@1.8.0 check

What it printed on a fixture repo

Historical CLI 1.7.2 capture. The current command above uses 1.7.8; its output can differ.

On 2026-10-23 we ran it on a small Next.js fixture repo made for this page, not a customer repo. Its app/api/webhooks/stripe/route.ts read the event with await req.json() and acted on event.type without verifying it. The output is below, with the temp folder shortened to ~/stripe-app. A warning is not a blocker, so the exit code was 0.

After the route read await req.text() and the stripe-signature header and called constructEvent, as in the example below, the same command reported no warnings.

Output
$ npx -y viberaven@1.7.2 check

viberaven check · ~/stripe-app

🟡 Stripe webhook does not verify the signature  (unverified_stripe_webhook)
   1 Stripe webhook handler without signature verification over the raw body: app/api/webhooks/stripe/route.ts (no signature check (constructEvent), no stripe-signature header, no raw body). Anyone who finds the URL can post a fake event, for example a paid checkout.

Verdict: ✅ no blockers, 1 warning · score 90
Fix: viberaven fix · Details: ~/stripe-app/.viberaven/agent-tasklist.md

Next.js App Router Stripe webhook example

A route handler at app/api/webhooks/stripe/route.ts. Stripe's own Next.js App Router example in the stripe-node repository does the same: constructEvent(await req.text(), signature, secret), and a 400 response when it throws.

Code
import Stripe from 'stripe';

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

export async function POST(req: Request) {
  const body = await req.text();
  const signature = req.headers.get('stripe-signature');
  let event: Stripe.Event;
  try {
    event = stripe.webhooks.constructEvent(body, signature!, process.env.STRIPE_WEBHOOK_SECRET!);
  } catch (err) {
    return new Response(`Webhook Error: ${(err as Error).message}`, { status: 400 });
  }
  if (event.type === 'checkout.session.completed') {
    // grant access
  }
  return Response.json({ received: true });
}

Do I need bodyParser: false in the App Router?

No. The Next.js docs say that, unlike API routes in the Pages Router, a route handler needs no bodyParser configuration to receive a webhook. The setting belongs to the Pages Router: there, Stripe's troubleshooting guide says to turn off bodyParser for the webhook route and read the raw buffer.

Stripe webhook on the edge runtime

On the default Node.js runtime, constructEvent works. A runtime that verifies with the Web Crypto API, such as a Supabase Edge Function on Deno, needs the async constructEventAsync instead, as in Supabase's own example.

Set up the route, then test it

  1. 1
    Find a webhook route that never reads the raw body. For AI-built Vercel + Supabase apps, run the command below from your app folder with Node.js 20 or newer. It reads your Stripe webhook handlers and reports unverified_stripe_webhook for a route that reads no raw body (await req.text(), req.arrayBuffer() or an Express raw parser), reads no stripe-signature header, never calls constructEvent or passes JSON.stringify(...) to it.
    Terminal
    npx -y viberaven@1.8.0 check
  2. 2
    Put the handler in app/api/webhooks/stripe/route.ts and export a POST function.
  3. 3
    Read the body once, with await req.text(), before anything else reads it. NextRequest extends the Web Request, so req.text() works with either type.
  4. 4
    Read the signature with req.headers.get('stripe-signature') and pass both to constructEvent with the endpoint's whsec_ secret.
  5. 5
    Make sure middleware or proxy code does not redirect /api/webhooks/stripe, for example to a sign-in page. Stripe treats a 3xx response as a failed delivery.
  6. 6
    Test locally with the Stripe CLI. Set STRIPE_WEBHOOK_SECRET to the secret stripe listen prints, then send an event:
    Terminal
    stripe listen --forward-to localhost:3000/api/webhooks/stripe
    stripe trigger checkout.session.completed
  7. 7
    Verify the signature, durably hand the event to a queue or persist it for processing, then return a 2xx quickly. Process slow fulfillment work in an idempotent worker; do not rely on untracked work continuing after the response. Stripe retries timed-out deliveries, and a successful response alone does not prove that access was granted.

Test a valid webhook as well as the rejected requests

On 2026-10-24 we compared two explicitly coded local handlers with Node.js 24.12.0 and stripe-node 17.7.0. One parsed and reserialized the JSON before verification; the other preserved the raw body. No Stripe account, network delivery, Next.js server, database, fulfillment or product execution was involved.

Three rejected bad requests can hide a broken handler

The payload was signed with a made-up local secret using the SDK test-header helper. The changed-body case contains the same JSON value with different whitespace, but retains the signature for the original bytes. All three rejection cases returned 400 in both handlers; only the valid request distinguished the broken handler from the working signature boundary.

Observed response status in the disposable local fixture, not live Stripe delivery.
RequestParsed and reserialized bodyOriginal raw body
Valid signature and exact original bytes400, wrong rejection200
Invalid signature400400
Missing signature400400
Same JSON, changed bytes, original signature400400

Repeat the checks against your actual route

The downloadable example only compares local signature handlers. To reproduce that example, use a disposable Node.js 20+ test project, install stripe@17.7.0 there, save the example file and run it with node. To verify your app, adapt these four cases to call your actual route with its local test signing secret. Do not use a real endpoint secret in a public test file.

After signature handling passes, separately test the behavior you sell: a valid event must persist the intended access change, a duplicate must not grant twice, and a failed durable handoff must not be acknowledged as successfully accepted. These business and delivery checks were not executed in this fixture.

Official docs behind this checklist

FAQ for builders before launch

Why does req.json() break the signature?

Stripe signs the exact bytes it sends. Parsing them and serializing again can change whitespace and key order, so the string you verify is no longer the one Stripe signed.

Can I read the body as an ArrayBuffer instead?

stripe-node accepts a string or a Buffer, so Buffer.from(await req.arrayBuffer()) works as well. What matters is that nothing parses the body before verification.