Nextjs app dir & Stripe error: StripeSignatureVerificationError
Unanswered
West African Lion posted this in #help-forum
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:
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?
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 executedSo 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 Lion Hi,
I've been browsing a lot of threads but unfortunately can't find a working solution. I have this code in a route:
js
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?
it seems like a stripe issue. You might want to refer to the offical stripe discord (of course with dev help): https://discord.gg/stripe
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 👍