Configuring the Change Email Script for Custom Database Connections
This article describes how to avoid the error that occurs when updating a user's email address on a Custom Database connection that lacks a configured change_email script.
When attempting to update a user's email, the following error message displays:
change_email script does not exist
- Custom Database Connection
- change_email script
Follow these guidelines and steps to configure or update the change_email script.
-
Manual Changes: If a user’s email is manually changed in the legacy custom database, the user's profile must be updated separately in the Auth0 database. Auth0 does not automatically detect manual changes in the legacy DB.
- Management API: To prevent accidental removal of an existing change email script, use the Management API or Deploy CLI when managing the connection.
-
Deploy CLI: When managing the environment using the Auth0 Deploy Command Line Interface (CLI) tool, database scripts are saved into separate
.jsfiles during the tenant configuration export. These are typically located underdatabase-connections/<connection-name>/get_user.js.
Retrieving the Current Script
Before changing or updating the script, retrieve the current configuration using the Management API.
-
Call the
GET /api/v2/connections/<id>endpoint. -
Locate the script inside the
options.customScriptsobject as a string.-
If no "change email" script is configured for that connection, the
change_emailkey is absent from thecustomScriptsobject.
-
Updating the Script
To configure or update the script for a custom database connection with Import Mode off, perform the following request:
-
Send a
POSTorPATCHrequest to the following URL: -
Use the following sample request payload:
{
"options": {
...
"customScripts": {
...
"change_email": "function changeEmail (email, newEmail, verified, callback) {\n return callback(null, true);\n}",
...
},
...
},
...
}
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.
-
Verify the configuration results in the following script:
function changeEmail (email, newEmail, verified, callback) {
return callback(null, true);
}