How to Change Username with Custom Database Connection

Problem statement

There is a change_email script that can be enabled for custom database connections with the Management API, but is there a way to change a username as well?

Solution

There is also a change_username script for Custom Database connections, though the script must also be added in the list of action scripts via the Management API.

While not included with the docs for the Custom Database Action Scripts, the change_username script functions the same as the change_email and ends with return(null, true) to indicate success:

https://auth0.com/docs/connections/database/custom-db/templates/change-email

"change_username": "function changeUsername(oldUsername, newUsername, callback) { console.log("ChangeUsername called")
callback(null, true);}"