Next.js Discord

Discord Forum

Nextjs app dir & Stripe error: StripeSignatureVerificationError

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
Hi,
I've been browsing a lot of threads but unfortunately can't find a working solution. I have this code in a route:
export const POST = async (req: NextRequest) => {
  const rawBody = await req.text();
  const sig = req.headers.get('Stripe-Signature') as string;
  let event;
  try {
    event = stripe.webhooks.constructEvent(rawBody, sig, process.env.STRIPE_ENDPOINT_SECRET || '');
  } catch (err) {
    const e = err as { statusCode: number; message: string };
    return Response.json({ error: { message: `Webhook Error: ${e.message}` }, status: e.statusCode || 400 });
  }
  // Rest of the code that would be executed

So here are the things I've done so far:
- used await req.text() to get the raw body
- verified that stripe secret key was correct
- verified that endpoint secret was correct
- compared payload and rawBody, they do match

But still I have the StripeSignatureVerificationError, I can't really figure out why. Any clue?

7 Replies

West African LionOP
Thanks
happy to help. Please mark solution
Uhh that’s not really a solution. If OP finds the solution, they can (and should) post here and self-mark.
Yes
alright 👍