Your Cart

Fixing “change_email script does not exist” on Auth0

If you’re seeing that error then you probably have a custom DB connection on Auth0, and the problem is that Auth0 could change the email for the user, but they don’t know how to change it on your database.

The solution is to write a script showing Auth0 how to do it, similar to the login, create, verify scripts you have on the Database -> Custom Database page. Since this is a one time update, you can use the handy Auth0 Management API page. First thing you’ll have to do is authenticate yourself, so go to your Auth0 control panel, select the appropriate API, and go to the “API Explorer” tab. There you can generate a token, which you can copy and paste onto the top left of the Auth0 Management API page.

Next, you’ll need to select the right connection, so scroll down to Get All Connections and hit “Try”. Get the connection ID of the one you want to add the change_email script too, and then scroll down to Get A Connection. Enter in the ID from before and you’ll be returned a new JSON object, you’ll want to save this to a separate text file. We’ll need this because the update connections endpoint will overwrite everything, not just the one section you want to change.

Now you’re ready to add your new script, here’s the boilerplate, and it’ll function just like the login/create/verify/delete scripts you already have.

function changeEmail(oldEmail, newEmail, emailVerified, callback) {  // change the email and email_verified flags in your internal DB if needed  ...]  // notify if the change was done  var changeWasSuccessful = true;  callback(null, changeWasSuccessful);}

After you’re done the script, you’ll need to convert it to a JSON. I think Auth0 jsonFN to convert their objects, so you’ll use the same. Here’s a JSFiddle where you can paste your function into.

Now copy that string and add it to the “customScripts” object from Auth0, so it ends up looking like this:

"options": {    ...,    "customScripts": {      "login": "...",      "get_user": "...",      "change_email": "...",      ...    }  }}

Lastly, you’ll need to send the changes to Auth0 by going to the Update a Connection section. BE VERY CAREFUL as this is live, and can break your host. It’s good to backup your original connection so you can always revert back to it. Hope this has helped and good luck!

Here’s a related question on the Auth0 community forums: https://community.auth0.com/t/change-a-user-email-when-using-custom-database/9567

SHARE: