Skip to main content
Docs

verifyWebhook()

Verifies the authenticity of a webhook request using Standard Webhooks. Returns a promise that resolves to the verified webhook event data.

function verifyWebhook(request: Request, options: <code>{ signingSecret?: string; }</code>): Promise<WebhookEvent>
  • Name
    request
    Type
    Request
    Description

    The request object.

  • Name
    options
    Type
    { signingSecret?: string; }
    Description

    Optional configuration object.

  • Name
    options.signingSecret?
    Type
    string
    Description

    The signing secret for the webhook. It's recommended to use the CLERK_WEBHOOK_SIGNING_SECRET environment variable instead.

Example

See the guide on syncing data for more comprehensive and framework-specific examples that you can copy and paste into your app.

import { verifyWebhook } from "@clerk/backend/webhooks";

export async function POST(request: Request) {
  try {
    const evt = await verifyWebhook(request);

    // Access the event data
    const { id } = evt.data;
    const eventType = evt.type;

    // Handle specific event types
    if (evt.type === "user.created") {
      console.log("New user created:", evt.data.id);
      // Handle user creation
    }

    return new Response("Success", { status: 200 });
  } catch (err) {
    console.error("Webhook verification failed:", err);
    return new Response("Webhook verification failed", { status: 400 });
  }
}

Feedback

What did you think of this content?

Last updated on