Skip to content

verifyWebhook

function verifyWebhook(
request,
secret,
options?
): Promise<WebhookEnvelope>;

Defined in: src/receiver.ts:48

Verify an incoming Request: reads the raw body, checks the Standard Webhooks headers and signature(s), and returns the parsed envelope. Throws WebhookVerificationError on any failure.

Parameter Type
request Request
secret string | string[]
options? VerifyWebhookOptions

Promise<WebhookEnvelope>

import { verifyWebhook } from "@xtandard/webhooks/receiver";
// In any fetch-style handler:
async function handler(request: Request): Promise<Response> {
try {
const event = await verifyWebhook(request, process.env.WEBHOOK_SECRET!);
console.log(event.type, event.data);
return new Response("ok");
} catch {
return new Response("invalid signature", { status: 401 });
}
}