fix(webhook): normalize event names to uppercase for case-insensitive matching
Some checks failed
Build and Deploy / build (push) Has been cancelled
Some checks failed
Build and Deploy / build (push) Has been cancelled
Saleor sends event names in lowercase (order_created) but our code expects uppercase (ORDER_CREATED). This fix normalizes the event name before checking supported events.
This commit is contained in:
@@ -412,14 +412,17 @@ export async function POST(request: NextRequest) {
|
||||
return NextResponse.json({ error: "Missing saleor-event header" }, { status: 400 });
|
||||
}
|
||||
|
||||
if (!SUPPORTED_EVENTS.includes(event)) {
|
||||
console.log(`Event ${event} not supported, skipping`);
|
||||
// Normalize event to uppercase for comparison
|
||||
const normalizedEvent = event.toUpperCase();
|
||||
|
||||
if (!SUPPORTED_EVENTS.includes(normalizedEvent)) {
|
||||
console.log(`Event ${event} (normalized: ${normalizedEvent}) not supported, skipping`);
|
||||
return NextResponse.json({ success: true, message: "Event not supported" });
|
||||
}
|
||||
|
||||
const payload = body;
|
||||
|
||||
await handleSaleorWebhook(event, payload);
|
||||
await handleSaleorWebhook(normalizedEvent, payload);
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user