How to Update the Change Email Custom Database Script Template

Overview

The error is triggered upon trying to update a user’s email that corresponds to a Custom Database connection that does not have a change_email script configured:

change_email script does not exist

Applies To

  • Custom Database Connection
  • change_email script

Solution

The change_email script does not exist error is triggered upon trying to update a user’s email that corresponds to a Custom DB connection that does not have a change_email script configured. The script is required for this operation because Auth0 must update the email on the store and on the profile on the Auth0 side, so it is not possible to do it without the change_email script.

On the other hand, having the script not properly implemented and not doing anything within the change_email script can cause issues on further logins for the user changing the email, so it is not recommended, given that it would not be serving its purpose. In this case, Auth0 would update the email on the Auth0 side and not on the database side, so the next time the user logs in with the new email, Auth0 would try to search for it on the database and would not find it, considering as an inexistent user. Unfortunately, the script has to be correctly implemented to reach out to the database and update the email in there as well in order to return a callback(null, true).

This is explained in detail here.

Below is an example to configure/update the change_email script for a custom DB connection with the Import Mode off:

POST/PATCH: https://{your_domain}/api/v2/connections/{con_id}

Sample request payload:

{
    "options": {
        ...
        "customScripts": {
            ...
            "change_email": "function changeEmail (email, newEmail, verified, callback) {\n  return callback(null, true);\n}",
            ...
        },
        ...
    },
    ...
}

While updating the details for the specific connection, make sure to include all existing option properties.

NOTE: If the options parameter is used, the entire options object is overridden. To avoid partial data or other issues, ensure all parameters are present when using this option.

The above would result in configuring the change_email script like below:

function changeEmail (email, newEmail, verified, callback) {
  return callback(null, true);
}