# Read from roles useAuth0 SDK hook

**URL:** <https://community.auth0.com/t/read-from-roles-useauth0-sdk-hook/75265>\
**Category:** Get Help\
**Created:** [December 21, 2021, 8:14am UTC](https://community.auth0.com/t/read-from-roles-useauth0-sdk-hook/75265 "2021-12-21T08:14:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![charlie](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/charlie/32/31260_2.png) [@charlie](https://community.auth0.com/u/charlie)\
**Post date:** [December 21, 2021, 8:14am UTC](https://community.auth0.com/t/read-from-roles-useauth0-sdk-hook/75265/1 "2021-12-21T08:14:11Z")

</div>

- **SDK:** auth0-react
- **SDK Version:** 1.8.0
- **Platform Version:** Node 16.13.1

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.

![image](https://global.discourse-cdn.com/auth0/original/3X/f/a/fa014692b21d8be1fe003234970261ac5937b8b9.png)

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?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [December 30, 2021, 10:16pm UTC](https://community.auth0.com/t/read-from-roles-useauth0-sdk-hook/75265/3 "2021-12-30T22:16:26Z")

</div>

Hi @charlie,

Thanks for reaching out to the Auth0 Community!

First, could you please clarify how you assigned the Roles to your users? Did you use the Management API?

And could you clarify if you saved the Roles using RBAC or just directly to the user’s profile?

Thank you.

---

<div class="post-metadata">

**Author:** ![charlie](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/charlie/32/31260_2.png) [@charlie](https://community.auth0.com/u/charlie)\
**Post date:** [December 30, 2021, 10:26pm UTC](https://community.auth0.com/t/read-from-roles-useauth0-sdk-hook/75265/4 "2021-12-30T22:26:39Z")

</div>

Happy to clarify. Roles are assigned to a user’s profile [in the Dashboard](https://auth0.com/docs/authorization/rbac/rbac-users/assign-roles-to-users). Then, I am adding user roles to a token in a [post-login trigger](https://auth0.com/docs/actions/triggers/post-login#add-user-roles-to-id-and-access-tokens).

Is this the best approach?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 3, 2022, 7:17pm UTC](https://community.auth0.com/t/read-from-roles-useauth0-sdk-hook/75265/5 "2022-01-03T19:17:41Z")

</div>

Hi @charlie,

Thank you for your response.

> [@charlie](#):
>
> How do I now check the user roles?

First, to check the user’s Roles you can use the Management API v2 [Get user role endpoint](https://auth0.com/docs/api/management/v2#!/Users/get_user_roles) to see the list of Roles assigned to them. This is one approach for getting the user’s roles.

You could also use it in conjunction with the [Get a user’s permissions endpoint](https://auth0.com/docs/api/management/v2#!/Users/get_permissions) to determine the authorization granted to the user.

Hoped this helps!

Please let me know how this works for you.

Thank you.

---

<div class="post-metadata">

**Author:** ![charlie](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/charlie/32/31260_2.png) [@charlie](https://community.auth0.com/u/charlie)\
**Post date:** [January 3, 2022, 8:05pm UTC](https://community.auth0.com/t/read-from-roles-useauth0-sdk-hook/75265/6 "2022-01-03T20:05:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 3, 2022, 8:35pm UTC](https://community.auth0.com/t/read-from-roles-useauth0-sdk-hook/75265/7 "2022-01-03T20:35:42Z")

</div>

Hi @charlie,

Thank you for your response and clarification.

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.

Does that help?

Thanks.

---

<div class="post-metadata">

**Author:** ![charlie](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/charlie/32/31260_2.png) [@charlie](https://community.auth0.com/u/charlie)\
**Post date:** [January 4, 2022, 1:51pm UTC](https://community.auth0.com/t/read-from-roles-useauth0-sdk-hook/75265/8 "2022-01-04T13:51:41Z")

</div>

Thanks for hanging in there with me, @rueben.tiow. I can’t seem to locate that method in the useAuth0 hook docs. Trying this throws an error:

```auto
const claims = useAuth0.getIdTokenClaims()
console.log(claims)

```

Are we sure this method is available in the Auth0 React SDK’s useAuth0 hook?

`_auth0_auth0_react __WEBPACK_IMPORTED_MODULE_1__.useAuth0.getIdTokenClaims is not a function`

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 5, 2022, 6:01pm UTC](https://community.auth0.com/t/read-from-roles-useauth0-sdk-hook/75265/9 "2022-01-05T18:01:59Z")

</div>

Hi @charlie,

Thank you for the response.

Please take a look at [https://auth0.github.io/auth0-react/modules/use\_auth0.html](https://auth0.github.io/auth0-react/modules/use_auth0.html) for the reference on `getIdTokenClaims`.

Let me know how this works for you.

Thanks.

---

<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:** [January 20, 2022, 6:02pm UTC](https://community.auth0.com/t/read-from-roles-useauth0-sdk-hook/75265/10 "2022-01-20T18:02:54Z")

</div>

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