Configuring the Change Email Script for Custom Database Connections

Overview

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

 

Applies To
  • Custom Database Connection
  • change_email script
Solution

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 .js files during the tenant configuration export. These are typically located under database-connections/<connection-name>/get_user.js.

 

Retrieving the Current Script

Before changing or updating the script, retrieve the current configuration using the Management API.

  1. Call the GET /api/v2/connections/<id> endpoint.

  2. Locate the script inside the options.customScripts object as a string.

    • If no "change email" script is configured for that connection, the change_email key is absent from the customScripts object.

Updating the Script

To configure or update the script for a custom database connection with Import Mode off, perform the following request:

  1. Send a POST or PATCH request to the following URL:

    https://<your_domain>/api/v2/connections/<con_id>

  2. 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.

  1. Verify the configuration results in the following script:

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

Recommended content

No recommended content found...