My very simple goal is to push role information onto a user, then use that role information in my app. I was able to accomplish the first step. I now see assigned roles when I log the user object.
How do I now check the user roles? The array containing the roles seems to have an inaccessible namespace. What do I need to do programmatically determine, “Is the user in X role?” What roles is Y user assigned?
First, to check the user’s Roles you can use the Management API v2 Get user role endpoint to see the list of Roles assigned to them. This is one approach for getting the user’s roles.
Thanks Rueben. I’m already connected with the auth0-react SDK. Is there nothing in the SDK to verify role assignment? I’m looping over the array containing the roles, but it feels like a hack.
After checking the Auth0 React SDK’s useAuth0 hook, you could use the getIdTokenClaims method to get the user’s roles after appending them as a custom claim using the Post-Login Action as you mentioned earlier.
This way, you could programmatically check the list of roles assigned to the user. Doing so is the preferred approach to check for the user’s roles.