mergeUser()
Merges the fromUserId user into the given user: moves its identifications, connected accounts, second factors, organization memberships, and metadata onto the given user, then deletes the fromUserId user. Where both users have a value, the given user keeps its own.
A merge cannot be undone. Use dryRun to preview one.
Returns the remaining User after the merge, and the deleted user as it was before the merge.
function mergeUser(userId: string, params: { dryRun?: boolean; fromUserId: string }): Promise<UserMergeResult>- Name
userId- Type
string- Description
The ID of the user that remains after the merge.
- Name
params- Type
{ dryRun?: boolean; fromUserId: string; }- Description
The parameters for the merge.
- Name
params.dryRun?- Type
boolean- Description
Whether to return the result of the merge without changing anything. Defaults to
false.
- Name
params.fromUserId- Type
string- Description
The ID of the user to merge into the other user. This user is deleted.
Preview a merge
Use dryRun to preview the result without changing either user.
const userId = 'user_123'
const fromUserId = 'user_456'
const preview = await clerkClient.users.mergeUser(userId, { fromUserId, dryRun: true })Merge users
Review the preview, then omit dryRun to merge the users. This deletes the fromUserId user and revokes its sessions.
const userId = 'user_123'
const fromUserId = 'user_456'
const response = await clerkClient.users.mergeUser(userId, { fromUserId })Backend API (BAPI) endpoint
This method in the SDK is a wrapper around the BAPI endpoint POST/users/{user_id}/merge. See the BAPI reference for more information.
Feedback
Last updated on