I was having issues Verifying the webhook from Clerk in Next.js using App Router.
The following worked for me.
import { Webhook } from "svix";
export async function POST(req: NextRequest) {
const svix_id = req.headers.get("svix-id") ?? '';
const svix_timestamp = req.headers.get("svix-timestamp") ?? '';
const svix_signature = req.headers.get("svix-signature") ?? '';
const body = await req.text(); // This get's the raw body as a string
const sivx = new Webhook("your_secret_key_here")
const payload = sivx.verify(body, {
"svix-id": svix_id,
"svix-timestamp": svix_timestamp,
"svix-signature": svix_signature,
});
// The payload is the json.
console.log(payload);
// The rest of your code
return NextResponse.json(null, { status: 200 })
}
For reference:
https://developer.mozilla.org/en-US/docs/Web/API/Response/text