Lower case user Id in profile or custom registration rule to make sure user_id is all lower case

Is there anyway to return a user profile response with following fields in lowercase irrespective of how they’re stored in Auth0 profile:

  • sub
  • user_id
  • _id

Further: We already have some users registered with Upper Case characters in their user id filed. In future, is there a way to register the user with all lower case irrespective of how the user entered in the front-end, we’d like to do this inside Auth0?

Note: We’re looking for this because we’re using subject as the user_id in our domain and our PROD expects all lower case characters, we have some users who’s id in Auth0 is stored with mixed case characters.

Please suggest.

I don’t believe there is any way to have Auth0 automatically lowercase those fields for you and there is no way to change the user_id.

This is a bit off topic but you might consider using your own UUID instead of Auth0’s user_id, and using that in your internal systems. The following rule will add a version 4 UUID to a user, if they don’t have one:

function (user, context, callback) {
    // Generates a version 4 random UUID. Namespace UUIDs do not appear
    // to be an option in Auth0 at this time.
    const uuid = require('uuid');
    
    user.app_metadata = user.app_metadata || {};
    user.app_metadata.uuid = user.app_metadata.uuid || uuid();
    
    auth0.users.updateAppMetadata(user.user_id, user.app_metadata)
        .then(function(){
            callback(null, user, context);
        })
        .catch(function(err){
            callback(err);
        });
}
2 Likes

Thanks Mark.

We ended up changing our application to take care of this. Further, we updated the JS to send all lower case before submitting the registration form.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.