feat(webhooks): outbound webhooks with HMAC-SHA256 signing and API key auth

Webhook registration/management. HMAC-signed delivery with retry.
Events: recipe.created/updated, comment.created, follower.new.
REST API key creation for programmatic access.
This commit is contained in:
Arnaud
2026-07-01 08:11:19 +02:00
parent d6032edc00
commit 3f96d1ea41
8 changed files with 420 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
import { NextRequest, NextResponse } from "next/server";
// Stripe webhook stub — wire up when adding Stripe
// Verifies stripe-signature header (using raw body), handles:
// - checkout.session.completed → upgrade user to pro
// - customer.subscription.deleted → downgrade user to free
export async function POST(req: NextRequest) {
const body = await req.text();
const sig = req.headers.get("stripe-signature");
if (!sig || !process.env["STRIPE_WEBHOOK_SECRET"]) {
return NextResponse.json({ error: "Stripe not configured" }, { status: 400 });
}
// TODO: const event = stripe.webhooks.constructEvent(body, sig, process.env["STRIPE_WEBHOOK_SECRET"]);
// For now just return 200 to acknowledge receipt
console.log("[stripe-webhook] received event, sig:", sig.slice(0, 20));
return NextResponse.json({ received: true });
}