How can get the name of the user in JWT token?

Using Auth0 Swift API:
When signing up using email + password, I include “name” field in user metadata.
When logging in I receive JWT token that has “name” field and it is always populated with user’s email. I want it to be populated with actual user’s name. How Do I let Auth0 know user’s name during registration and reflect it when logging in?

Hey there @oleh.naumenko welcome to the community!

Just to confirm, you are setting a name property in a user’s user_metadata currently? If that’s the case, you can use an Action to override the name claim in ID and/or access tokens using something like the following code:

exports.onExecutePostLogin = async (event, api) => {

 // Check if the user_metadata has the "name" key
  if (event.user.user_metadata && event.user.user_metadata.name) {
    // Set a custom claim in the ID Token
    api.idToken.setCustomClaim('name', event.user.user_metadata.name);
    // Set a custom claim in the Access Token
    api.accessToken.setCustomClaim('name', event.user.user_metadata.name);
  }
};

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