"Error! The Specified New Email Already Exists" - Custom DB Connections

Problem statement

A Custom Database connection with Import mode ON enables the creation of a user profile with email in the Username.

According to the documentation Adding usernames for database connections, it should not allow storing email as the username.

When trying to change a user’s email address to the one used as the username, or signing up a new user with that email address (regular sign up or through the Management API “POST /api/v2/users”), an error is thrown:

Error!The specified new email already exists

or

The user already exists

However, a search for a user with that email address, using either the search function in the Dashboard or the Management API Get-Users-By-Email endpoint, does not result in that user being found.

Steps to Reproduce

  1. Create a Custom DB connection to return the user profile with: username: user.email and email: user.email

Sample code:

callback(null, {
user_id: 'emailname-1',
nickname: '[testuser@test.com](mailto:testuser@test.com)',
email: '[test@test.com](mailto:test@test.com)',
username: '[testuser@test.com](mailto:testuser@test.com)'
});
  1. Turn import mode ON
  2. Login with the user’s email ‘test@test.com
  3. This creates a user profile in the Dashboard as:

Username: testuser@test.com
email: test@test.com

  1. Update the Connection’s Get User script to ​​NO-OP functions
function getByEmail(email, callback) {
return callback(null, null);
}
  1. Update the Email field with email other than the one in Username
  2. Now, try updating the Email field to ‘testuser@test.com’ (email in Username). It throws an error 'Error!The specified new email already exists'
  3. Also, it is not allowing to create a new user with email as the one in username ’

Cause

Normally Auth0 will not allow users to be created with emails for usernames, but for a custom DB, Auth0 will just replicate what was returned by the Custom DB action scripts.

If using the Management API endpoint for getting users by email, it will only search by the email field, so users will not be returned for that email address, but the update API will also check other user identifiers for conflicts, and the user exists error will be displayed.

Solution

A backlog item has been created to fix this issue.

As an alternative, it is suggested to export and reimport the users to remove the username attributes entirely:

  1. Export the entire set of users.
  2. Trim off all the usernames from the resulting export.
  3. Re-import it into a new database connection.