Guide

Clerk webhooks: receive and verify Svix-signed events locally

Clerk webhooks tell your backend when a user signs up, updates their profile or joins an organization, so you can keep your own database in step. Clerk delivers them through Svix, which signs every event. Here is how to add an endpoint, verify the Svix signature and test user events against a handler on localhost.

All docs

Get a public URL for Clerk webhooks#

Clerk can't deliver to localhost. An OtterKit webhook endpoint gives you a public HTTPS URL that answers Clerk around the clock and keeps every request, so nothing is lost while your laptop is closed or your handler is half written:

Terminal
npx otterkit login
npx otterkit webhook --daemon --subdomain clerk-dev
#   https://clerk-dev.otterkit.app

The name is reserved to your account, so the URL stays the same every time you start it. An endpoint costs $0.01 per hour while it is live and never more than $3 in any 30 days, and new accounts get 10 free credits. To look at a payload before you sign up, the try page gives you a live URL in the browser with no account.

Register the URL in Clerk#

  1. In the Clerk Dashboard, open Webhooks and click Add Endpoint.
  2. Paste the endpoint URL and choose the events, for example user.created and user.updated.
  3. Create it, then copy the Signing Secret from the endpoint's page. It starts with whsec_.

Use https://clerk-dev.otterkit.app as the URL. Add a path if your handler expects one, such as https://clerk-dev.otterkit.app/api/webhooks/clerk: the endpoint accepts any path and records it.

Verify the Svix signature#

Each delivery has three headers: svix-id, svix-timestamp and svix-signature. The signature is an HMAC-SHA256 of the ID, the timestamp and the raw body joined with dots, base64-encoded and prefixed with v1,. Clerk's SDKs and the svix package do the check for you; pass them the raw body.

Development and production instances are separate in Clerk: each has its own endpoints and its own signing secrets.

OtterKit can run the same check on every request as it arrives. Start the endpoint again with the secret, and each capture is marked valid, invalid or missing:

Terminal
npx otterkit stop clerk-dev
npx otterkit webhook --daemon --subdomain clerk-dev --verify svix:whsec_…

A failed check comes with its reason, such as signature_mismatch, so a wrong secret and a changed body look different. See signature verification for all 16 presets and the generic HMAC mode.

Send a test event#

Open the endpoint in the Clerk Dashboard, go to the Testing tab, pick an event and send an example. For a real one, sign up a test user in your development instance.

Then watch it land, or wait for it in a script:

Terminal
# Follow requests as they arrive, with headers and bodies
npx otterkit inspect clerk-dev --follow

# Or block until the next POST, then print it as JSON
npx otterkit await clerk-dev --method POST --count 1 --timeout 120s --json

Replay Clerk events into your local handler#

Once an event is captured you can send it to your handler as often as you like, with the original headers and body, without asking Clerk to fire it again:

Terminal
# Send the latest captured event to a server on port 3000
npx otterkit replay clerk-dev --target 127.0.0.1:3000

# Or a specific one (1 is the oldest, -1 the latest)
npx otterkit replay clerk-dev --index 3 --target 127.0.0.1:3000

Replays cost nothing and are added to the capture log with your handler's response next to them. If you would rather have events delivered live while you work, expose the handler with a tunnel instead and register the tunnel URL.

Retries, timeouts and duplicates#

  • Svix retries a failed delivery on a schedule that stretches over hours, and the endpoint's page lists every attempt with its response. You can resend any message from there.
  • Webhooks arrive after the fact and sometimes late. Don't make a sign-up flow wait on one.

To see how your code copes when a delivery fails, the HTTP status codes guide has URLs that return any status on demand.

Questions about Clerk webhooks#

Why do Clerk webhooks have svix headers?#

Clerk uses Svix to deliver its webhooks, so the signature scheme is Svix's.

My webhook route returns 401 or a redirect. Why?#

Your auth middleware is protecting it. Make the webhook route public: the signature is what authenticates the request.

Should I sync users to my database with webhooks?#

It works well for keeping a copy up to date. For data you need during the request, read it from the session or Clerk's API instead of waiting for the event.

Other providers#