Hi,
We use our own email verification process. During an Action I would like to be able to update the auth0 users email_verified flag. I found other topics saying to use ManagementClient. I did this. The way it was coded in the post did not work. I had to added the API “audience” to the call. It now works but gets the error “ManagementApiError: change_email script does not exist”. I have search other posts but they all relate to Custom Database scripts, not actions. How do I update the email verify flag from an Action ?
Thank you for sharing - to help find out where the error may come from, I would like to understand the context this function runs in
The code shared is most likely a snippet of the bigger Action script, but I would like to make sure of that (?) What is the flow this function runs within?
Thanks for the reply. Yes, this is indeed a function from within an Post-login action.
Business flow:
User signs up to our external system (via Salesforce)
The external system sends a confirmation email containing a hyperlink with an auth0 login URL containing a verification code.
The user clicks the link in the email. During the auth0 login, we run a Post Login action.
In this action, if the user is not currently email_verified (ie. they are new) and the login URL contains a query string passing a verification code, we check that verification code with an external API call to our external system to validate the code. If the code is validated we activate the user in the external system.
If the user is activated in the external system, we also now want to set the email_verified from “pending” to “verified” in auth0. This is the function posted above. This call fails with the " change_email script does not exist " error. I just want to flag the user as now verified.
To start debugging, I reduced the complexity of the code to a minimum to see if we could update the user property email_verified = true in a Login Action.
To this end, I wrote an action script that checks if the above property holds a false value (replace with your own condition) and, if so, updates the property to true.
We use a Database connection because when the user is added to auth0 it must have previously been registered in Salesforce. In the Login script of the Custom Database, we call an API to confirm the username and password are correct in SF and then return some information. If valid, when create the user and update some metadata. The following Action called during this flow is the one that is failing.
From the comments provided on this thread, it sounds like you’re using a Custom Database Connection in Auth0. Correct? If so, then the error you’re seeing is likely due to the fact that - whilst you’ve created the Login script in you’re Custom Database Connection definition - you haven’t created a script for Change Email; the error in the Action context is actually a side-effect as a result of the missing script in the Custom Database Connection definition.
If you don’t need to do anything outside of Auth0, then simply implement the email change script in the Custom Database Connection definition as a no-op, as in:
function (email, newEmail, verified, callback) {
// Return `true` value in callback to signal operation succeeded
return callback(null, true);
}
Also, if you haven’t found it already, you may find our documentation on extensibility best practices to be helpful; see here for details.