# Auth0-angular access to users role

**URL:** <https://community.auth0.com/t/auth0-angular-access-to-users-role/131329>\
**Category:** Get Help\
**Tags:** user-profile, user-management\
**Created:** [April 5, 2024, 12:02pm UTC](https://community.auth0.com/t/auth0-angular-access-to-users-role/131329 "2024-04-05T12:02:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gxomalis](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@gxomalis](https://community.auth0.com/u/gxomalis)\
**Post date:** [April 5, 2024, 12:02pm UTC](https://community.auth0.com/t/auth0-angular-access-to-users-role/131329/1 "2024-04-05T12:02:57Z")

</div>

Hello! I’m very new to auth0. Im building this website in Angular with express node.js backend. I followed the tutorials to make login/logout and signup for my website, and now based on the user that has logged in the website, I want to render different parts.

I assigned my users “Admin”, and “User”, but for some reason after researching I haven’t got a solution. I can’t access the logged on user’s role.

In Angular I have a my auth0 service:

```auto
import { NgModule } from '@angular/core';
import { provideAuth0 } from '@auth0/auth0-angular';

@NgModule({
  providers: [
    provideAuth0({
      domain: 'XXXXXXXXXXX.eu.auth0.com',
      clientId: 'XXXXXXXXXXXXXXXX',
      authorizationParams: {
        redirect_uri: window.location.origin
      }
    })
  ]
})
export class Auth0Module {}

```

In the component I want to show the user’s role, in the .ts file I do this:

```auto
 user$ = this.auth.user$;
  code$ = this.user$.pipe(map((user) => JSON.stringify(user, null, 2)));

```

and on the .html file I get the user’s info with {{ user.nickname }}.

Also I used the Auth0 Authorization Extension and assigning Roles to my Users from there, gives the app\_metadata this:

```auto
{
  "authorization": {
    "roles": [
      "Admin"
    ]
  }
}

```

How can I get the user’s role that I assigned from the auth0 dashboard? Or how can I have access to the logged user app\_metadata to fetch the role from there?

Any help would be appreciated. Thanks in advance!

If you need more info so you can understand my problem and the level I am, let me know.

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [April 7, 2025, 4:38pm UTC](https://community.auth0.com/t/auth0-angular-access-to-users-role/131329/4 "2025-04-07T16:38:16Z")

</div>

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](https://auth0.com/docs/manage-users/access-control/sample-use-cases-actions-with-authorization#add-user-roles-to-tokens), which you can accomplish using an Action as described below:

```auto
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](https://github.com/auth0/auth0-angular/blob/main/EXAMPLES.md#display-the-user-profile) 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](https://auth0.com/docs/api/management/v2/users/get-users-by-id) profile.

This [community post](https://community.auth0.com/t/accesing-metadata/64750) should provide information on the matter as well.

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [April 21, 2025, 4:38pm UTC](https://community.auth0.com/t/auth0-angular-access-to-users-role/131329/5 "2025-04-21T16:38:57Z")

</div>

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