clerk-auth-webhook-handler
Version:
A type-safe webhook handler for Clerk webhooks with support for Svix
32 lines • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseClerkEvent = void 0;
const svix_1 = require("svix");
const parseClerkEvent = (params) => {
const { requestBody, requestHeaders, secret } = params;
console.log("webhook event", params.requestBody);
if (!secret) {
console.error("Error: Please add SIGNING_SECRET from Clerk Dashboard to .env");
throw new Error("Server configuration error: SIGNING_SECRET not found");
}
// Get the headers
const svix_id = requestHeaders["svix-id"];
const svix_timestamp = requestHeaders["svix-timestamp"];
const svix_signature = requestHeaders["svix-signature"];
// If there are no headers, error out
if (!svix_id || !svix_timestamp || !svix_signature) {
throw new Error("Missing Svix headers");
}
// Create new Svix instance with secret
const wh = new svix_1.Webhook(secret);
const body = JSON.stringify(requestBody);
// Verify the payload with headers
const evt = wh.verify(body, {
"svix-id": svix_id,
"svix-timestamp": svix_timestamp,
"svix-signature": svix_signature,
});
return evt;
};
exports.parseClerkEvent = parseClerkEvent;
//# sourceMappingURL=parse.js.map