Auth0-angular access to users role

Hi @gxomalis,

Welcome back to the Auth0 Community and sorry for the late reply.

Firstly you’ll have to Add user roles to the token, which you can accomplish using an Action as described below:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://my-app.example.com';
  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);  
  }
}

Then in your angular application you can display the user profile by accessing the user$ observable on the AuthService instance. This observable already heeds the isAuthenticated$ observable, so you do not need to check if the user is authenticated before using it. Please check our Auth0 Angular SDK for a detailed example.

You can then access the component’s user$ observable from within your template with a property such as user.roles.

Otherwise if you are trying to pass the metadata to your application, you’ll also have to pass that as a custom claim to the ID Token, then use the Management API to get the Get a user’s profile.

This community post should provide information on the matter as well.

Hope this helps the case, but others as well.
Thanks,
Remus