Overview
When specific events happen in Clerk (e.g., user signup, password changes, email verification), this integration will:- Receive the webhook event from Clerk.
- Verify the webhook signature.
- Process the event data.
- Trigger the corresponding Novu notification workflow.
You can also clone this repository: https://github.com/novuhq/clerk-to-novu-webhooks
Prerequisites
Before proceeding, ensure you have:- A Clerk + Next.js app (Set up Clerk).
- A Novu account (Sign up here).
Expose Your Local Server
To test webhooks locally, you need to expose your local server to the internet.There are two common options:- localtunnel
- ngrok
localtunnel is a simple and free way to expose your local server without requiring an account.
-
Start a localtunnel listener
-
Copy and save the generated public URL (e.g.,
https://your-localtunnel-url.loca.lt).
localtunnel links may expire quickly and sometimes face reliability issues.
Set Up Clerk Webhook Endpoint
- Go to the Clerk Webhooks page (link).
- Click Add Endpoint.
-
Set the Endpoint URL as:
-
Subscribe to the relevant Clerk events (e.g.,
user.created,email.createdetc.).
You can find the list of all supported Clerk events here, or proceed to the section which going over Identify the Triggering Event(s).
- Click Create and keep the settings page open.
Add Signing Secret to Environment Variables
- Copy the Signing Secret from Clerk’s Webhook Endpoint Settings.
- Add it to your
.env.localfile:
Create Webhook Endpoint for Clerk in Next.js
Createapp/api/webhooks/clerk/route.ts:app
api
Breakdown of the code
Breakdown of the code
Imports and Dependencies
-
Webhookfromsvix: This is a library used to verify the authenticity of incoming webhooks by checking their signatures. Webhooks often use signatures to ensure the payload hasn’t been tampered with. -
headersfromnext/headers: A Next.js utility to access HTTP headers from the incoming request in the App Router. -
WebhookEventfrom@clerk/nextjs/server: A type definition for webhook events, likely provided by Clerk (a user authentication and management service). This ensures type safety when handling events. -
triggerWorkflow: A custom function (imported from another file) that triggers a workflow. This is likely where notifications or other business logic is executed.
Event Mapping
Main Entry Point:
POST HandlerHandling the Webhook Event:
handleWebhookEventIdentify the WorkflowID based on the event type:
workflowBuilderBuilding the Subscriber:
subscriberBuilderBuilding the Payload:
payloadBuilderValidating the Headers:
validateHeadersVerifying the Webhook:
verifyWebhooksvix library.How It All Fits TogetherHere’s a high-level flow of how the code works:
-
Receive a Webhook:
The
POSThandler receives anHTTP POSTrequest with a webhook payload. -
Validate and Verify:
The
validateHeadersfunction ensures the required Svix headers are present. TheverifyWebhookfunction uses thesvixlibrary to verify the webhook’s authenticity. -
Process the Event:
The
handleWebhookEventfunction filters events and processes onlyuser.createdoremail.createdevents. It calls helper functions (workflowBuilder,subscriberBuilder,payloadBuilder) to construct the necessary data. -
Trigger a Workflow:
The
triggerWorkflowfunction is called with the constructed data, executing the desired business logic (e.g., sending notifications).
Add Novu Workflow Notification Trigger Function
Createapp/utils/novu.ts :app
utils
api
- Node.js
- Python
- Go
- PHP
- .NET
- Java
- cURL
Add or create Novu workflows in your Novu dashboard
In Novu, a webhook event—such as a user being created or updated—can trigger one or more workflows, depending on how you want to handle these events in your application.A workflow defines a sequence of actions (e.g., sending notifications, updating records) that execute when triggered by a webhook.The Novu dashboard allows you to either create a custom workflow from scratch or choose from pre-built templates to streamline the process.Steps to Create a WorkflowFollow these steps to set up your workflow(s) in the Novu dashboard:Identify the Triggering Event(s)
Determine which webhook events will activate your workflow (e.g., “user created,” “user updated”).Check your webhook configuration to understand the event data being sent.Supported webhook events
Supported webhook events
To find a list of all the events Clerk supports:
- In the Clerk Dashboard, navigate to the Webhooks page.
- Select the Event Catalog tab.
Payload structure
Payload structure
The payload of a webhook is a JSON object that contains the following properties:
-
data: contains the actual payload sent by Clerk. The payload can be a different object depending on the event type. For example, foruser.*events, the payload will always be the User object. -
object: always set toevent. -
type: the type of event that triggered the webhook. -
timestamp: timestamp in milliseconds of when the event occurred. -
instance_id: the identifier of your Clerk instance.
user.created event:Choose Your Starting Point
- Use a Workflow Template
- Create a Blank Workflow
- Code-First Workflow (Novu Framework)
Browse the workflow template store in the Novu dashboard. If a template matches your use case (e.g., “User Onboarding”), select it and proceed to customize it.
Configure the Workflow
- For a template, tweak the existing steps to align with your requirements.
- For a blank workflow, add actions like sending emails, sending in-app notifications, Push notifications, or other actions.
- For a code-first workflow, you can use the Novu Framework to build your workflow right within your code base.
Set Trigger Conditions
- Link the workflow to the correct webhook event(s).
- Ensure the trigger matches the event data (e.g., event type or payload) sent by your application.
Disable Email Delivered by Clerk
By default, Clerk sends email notifications whenever necessary, such as Magic Links for email verification, Invitations, Password Resets, and more.To prevent users from receiving duplicate emails, we need to disable email delivery by Clerk for the notifications handled by Novu.-
Navigate to the Emails section in the Clerk Dashboard.

- Select any email.created event that you want Novu to handle.
-
Toggle off email delivery for the selected event.

Test the Webhook
- Start your Next.js server.
- Go to Clerk Webhooks → Testing.
- Select an event (e.g.,
user.created,email.created). - Click Send Example.
- Verify logs in your terminal.