Auth0-angular access to users role

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:

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:

 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:

{
  "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.

1 Like