How can I get user's role when this user logged in


I read following references:

auth0 doc: ‘scope custom claims’
auth0 community topic: ‘read custom claims in angular’

But I still cannot figure it out. I use auth0-js, Angular2 and Node.js, and I installed Auth0 Authorization extension, so I’d like to get user’s role, like ‘admin’, when this user logged in. Before I add this feature in Angular service, I can get id_token, access_token and profile correctly, like in profile:

email: ***
email_verified: true
name: ***
nickname: ***
picture: ***
sub: auth0|***
updated_at: ***

I can get user’s nickname correctly to show, now I’d like to include ‘role’ in profile, since I use a method in auth.service:

    public getRoles(): Object {
        const appData = '';
        return this.getProfile()[appData].authorization.roles;

where is my domain, But I cannot see this info in profile in browser’s local storage, also browser console has exception:

cannot read property ‘authorization’ of undefined

I added a rule within outermost existed function in Rules:

function getRoles(user, context, callback) {
    const namespace = 'heeps://';
    context_idToken[namespace + 'app_metadata'] = user.app_metadata;
    callback(null, user, context);

I have no idea to solve this problem, can anyone help me? Thanks!

OK, seems I got it.
I think this question can be closed, thanks!

how did you solve it? :slight_smile:

1 Like