"User Already Exists" Error When Creating New User
This article addresses an issue where creating a new user or migrating a user to Auth0 fails with the following error:
User Already Exists
This error can occur even when a search for the email address or a query using the getByEmail API does not return any results for that user.
- Database Connections
- New Users
This error can be caused by two primary scenarios, particularly with Custom Databases (DBs):
-
Incorrect "Get User" Script: The "Get User" script for the Custom DB is executed before user creation. If the script is misconfigured and returns a user profile for a non-existent user (instead of null), Auth0 interprets this as the user already existing and blocks the creation.
-
Pending Password Reset: A user completed a password reset process but did not sign in afterward. This is common when a Custom DB with Import Mode ON is used. Auth0 stores the new password in a temporary record. This record may not appear in user searches but still conflicts with the new user creation, as it is linked to the same email address.
Follow the steps or video below:
Before proceeding, confirm the following:
-
The user is attempting to sign in, not create a new account.
-
The user does not appear in a search using the GET /api/v2/users endpoint.
To resolve this issue, investigate the two potential causes:
Solution 1: Correct the "Get User" Script
-
Navigate to the "Get User" script settings for the Custom DB.
-
Select the Test button to test the script.
-
Ensure the script is configured to return
nullwhen a user does not exist in the external DB.
Solution 2: Address Pending Password Reset
Choose one of the following recovery methods:
Option 1: User Sign-In
-
The user must sign in using the password they recently set.
-
If the user does not recall the password, they must initiate the password reset process again.
Option 2: Delete Temporary User Record
-
Use the Delete a connection user endpoint, DELETE /v2/connections/{id}/users, to remove the temporary user record from Auth0.
NOTE: If the user was able to perform a password reset, it implies the user already exists in the external DB. Deleting this Auth0 record removes the new password from Auth0's temporary storage. Consequently, the user will need to use their previous password (stored in the external DB) to sign in or reset their password again if that original password is not known.
Final Step
If the issue affects multiple users or persists after trying these solutions, contact support to request a re-indexing of the tenant users in the search index.