Is there a "change username" database connection script?

Hello. I’m looking to sync Auth0 identities back to my own database and need a callback each time a user’s email or username changes. This appears to be possible with email addresses, per: https://auth0.com/docs/connections/database/custom-db/templates/change-email

Is there an analogous hook that runs when a username is updated? If not, is there another way to achieve this?

Thanks.

Hi @greg.macwilliam ,

I’m afraid there isn’t a hook for a username change available currently like there is for a change in email, and that in turn is only available for Custom Databases in Legacy authentication mode.

However, assuming Auth0 is the IdP in your scenario, the only way to change a user’s username is to use the Management API’s “Update a user” PATCH endpoint. Therefore, you could integrate with the server side app/script making the PATCH call to also update your own database if the PATCH is successful to keep the two in sync.

If the username is coming from an upstream provider, you may want to turn off “Sync user profile attributes at each login” if you are making changes to username on the Auth0 side to avoid them being overwritten.

If on the other hand you are trying to detect changes upstream, then you may want to leverage ID tokens and/or the /userinfo endpoint to check your database’s copy is up to date with the latest authentication the user performed on the connection.

You can also add custom claims to ID tokens if you need information not available in the standard OIDC claims. This will also update the responses returned by the /userinfo endpoint.