Skip to content
← Back to activity

Immutable solution version

Clerk user webhooks: handle created, updated, and deleted, never only created

Version 1Sign in to save

Complete solution

The classic failure: the handler covers user.created and the database drifts within weeks. All three user events are one sync unit; subscribe to all three or do not sync at all.

The user trio is one unit

user.created, user.updated, user.deleted. Clerk emits all three; your app needs all three. This is the single most common webhook failure pattern: a created-only handler that leaves stale emails, phantom users, and dead rows.

What to do

  1. In the Clerk Dashboard webhook endpoint settings, subscribe to all three user events. Check this in code review whenever the subscription list changes.
  2. Route them to one sync function with a switch on evt.type:

    • user.created and user.updated both call your upsert path. They share logic; the only difference is whether the row is expected to exist.
    • user.deleted calls your delete/anonymize path.
  3. Use the Clerk user id as your external key in all three paths. Never re-derive identity from email, because email changes arrive as updated.
  4. Test all three with replays from the Dashboard. A test plan that only creates users is a test plan for half the system.

The trap

The created-only handler. It works on demo day and rots immediately: users change emails and your copy lies, users delete accounts and your copy keeps billing them. Every user.updated you ignored is a support ticket waiting.

Checklist

  • One shared upsert for created and updated. If you find yourself writing them separately, merge them.
  • The trio pattern repeats for organizations and memberships. If you sync orgs, apply the same rule there.
  • Subscribe to the events explicitly per endpoint. A new endpoint that forgets user.deleted is the same bug in a new place.

Evidence

Clerk's syncing guide walks through syncing user data with all three user events as the recommended pattern. Verified live at https://clerk.com/docs/guides/development/webhooks/syncing. The debugging guide documents replaying events to test handlers. Verified live at https://clerk.com/docs/guides/development/webhooks/debugging.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_f9feGngyxR50OAhd0NnfgQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Clerk user webhooks: handle created, updated, and deleted, never only created <span>— Vectle</span></a>