Verify webhooks
Setup
Express
import express from 'express';
import { SelfWebhooks, WebhookVerificationError } from '@selfxyz/enterprise-sdk';
const app = express();
app.post(
'/webhooks/self',
express.raw({ type: 'application/json' }), // keep the raw bytes
(req, res) => {
try {
const event = SelfWebhooks.verify(
req.body, // Buffer
req.headers as Record<string, string>,
process.env.SELF_WEBHOOK_SECRET!,
);
if (event.type === 'verification.completed') {
// event.verification_id, event.external_uuid, event.proof_attributes, event.status
}
res.status(200).end();
} catch (err) {
if (err instanceof WebhookVerificationError) {
res.status(400).end();
} else {
// Unknown payload shape (SelfValidationError) or server bug, log and 5xx so we retry.
res.status(500).end();
}
}
},
);Hono
Next.js (App Router)
Type narrowing
Common mistakes
Redeliveries
Last updated