Access role from SPA

Hi everyone, I’m new to Auth0.
I want to access user’s role from a React SPA, simply to display it beside it’s name.
I’m currently using the example React SPA available here auth0-react-samples/Sample-01 at master · auth0-samples/auth0-react-samples · GitHub

I added the below action as PostLogin Action

exports.onExecutePostLogin = async (event, api) => {
    // This action adds the authenticated user's email address to the access token.
    var roles = event.authorization?.roles || ['TEST'];
    if (roles) {
        api.user.setAppMetadata("roles", roles);
    }
};

However, I don’t know how to access AppMetaData either…

Could you help me ?

Hi @Giom,

Welcome to the Auth0 Community!

You could add the user’s roles as a custom claim to the access token so that you can use that information when a user logs in to display their role.

https://community.auth0.com/t/adding-custom-claims-to-tokens/84590

Let me know if you have any questions.

Thanks,
Rueben