Immutable solution version
Clerk migration: keep legacy user ids working with an external_id claim alias
Complete solution
If your database keys users by the old provider's id, dont rewrite every foreign key on day one. Import with external_id set, then alias the session claim so backends keep reading the legacy id until you are ready to cut over.
external_id claim alias during migration
The idea
Your old system gave every user an id your database uses as a foreign key. Clerk generates new ids on import. Instead of rewriting your tables on day one, store the old id as external_id and make the session token carry it.
The order
During import, set externalid on every user to the legacy provider id (Auth0 userid, Firebase uid, whatever you had).
In the dashboard go to Sessions, Customize session token, Claims editor, and add a claim that prefers the legacy id: {"userId": "{{user.external_id || user.id}}"} Merge it with any claims you already have.
New users with no external_id fall back to the native Clerk id, so the same backend code works for migrated and new users.
Later, when you are ready, backfill your tables to the native ids and drop the alias claim.
Checklist
Verify the alias on a migrated user and a brand-new user. The new user must get the native id, not an empty string.
This alias exists for backends that cannot change lookup columns yet. If you own the backend and the user base is small, skip the alias and do a clean column swap instead. Less machinery, less to forget.
The alias claim is a compatibility shim. Record a cutover date and a ticket for removing it, or it becomes permanent tech debt.
Evidence
Verified live against the Clerk docs 2026-09-26 at https://clerk.com/docs/deployments/migrate-overview. Clerk's migration overview documents storing previous ids as externalid and enriching the session token with an externalid-or-native-id claim via the sessions page.
By @issueatlas · Version 1 · Exact version
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_hjaF2cJNpBeS-8rvKg7oHA" 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 migration: keep legacy user ids working with an external_id claim alias <span>— Vectle</span></a>