# Access user permissions array in user token

**URL:** <https://community.auth0.com/t/access-user-permissions-array-in-user-token/83024>\
**Category:** JWT.io\
**Tags:** spa, react, permissions\
**Created:** [May 6, 2022, 10:54am UTC](https://community.auth0.com/t/access-user-permissions-array-in-user-token/83024 "2022-05-06T10:54:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkiddle](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tkiddle/32/37150_2.png) [@tkiddle](https://community.auth0.com/u/tkiddle)\
**Post date:** [May 6, 2022, 10:54am UTC](https://community.auth0.com/t/access-user-permissions-array-in-user-token/83024/1 "2022-05-06T10:54:45Z")

</div>

Why on earth is it so difficult to access a user’s “permissions” from within a react application?

I have a single-page application, and my user has some roles and permissions attached to it.

I can create a custom rule to add the “roles” to a custom namespace, but accessing the actual permissions is seemingly impossible.

Role access:  
`const assignedRoles = (context.authorization || {}).roles || [];`

I need the granularity of permissions in my react app, roles are too broad.

To be clear there seems to be some sort of solution here:

> [@How to get user permissions in SPA?](https://community.auth0.com/t/how-to-get-user-permissions-in-spa/39777):
>
> I successfully generated a SPA from the Quick start. Login/private routes, etc are working as expected. Now how do I get user permissions in order conditionally render the UI? I have added roles/permissions users and a rule [per this example](http://community.auth0.com/t/react-get-permissions-for-authenticated-user-through-auth0client-getuser/37593). Is this a common use case? I would think so but I can’t really find a clear answer wading through your docs.

But it is not clear if the call to the Management API `getUserPermissions` stated in that solution counts towards our API request limit?

Calling the management API each time a token is generated seems like a really expensive way to add permissions to a custom namespace, that can be accessed within our SPA.

---

<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:** [May 6, 2022, 6:08pm UTC](https://community.auth0.com/t/access-user-permissions-array-in-user-token/83024/3 "2022-05-06T18:08:11Z")

</div>

Hi @tkiddle,

Welcome to the Auth0 Community!

I understand you have questions about retrieving the user’s permissions from an ID Token when using Auth0’s React SDK.

> [@tkiddle](#):
>
> I can create a custom rule to add the “roles” to a custom namespace, but accessing the actual permissions is seemingly impossible.

Yes, this is the first step you will need to do and seems like you have already implemented a Rule to append the custom claims to the ID Token. In this case, the custom claims will include the user’s Roles and Permissions. Be careful when choosing your namespace identifier, and abide by the guidelines described [here](https://auth0.com/docs/secure/tokens/json-web-tokens/create-namespaced-custom-claims).

Next, you will want to use the [`useAuth0` hook](https://auth0.github.io/auth0-react/modules.html#useAuth0) from the Auth0 React SDK and call the `getIdTokenClaims` method.

This way, you avoid any expensive API calls or exceeding the Rate limit when using the Management API [Get a User’s Permissions](https://auth0.com/docs/api/management/v2#!/Users/get_permissions) and [Get a User’s Roles](https://auth0.com/docs/api/management/v2#!/Users/get_user_roles) endpoints.

Please let me know if you need more clarification or have any questions. I’d be happy to help.

Thanks.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 21, 2022, 4:11pm UTC](https://community.auth0.com/t/access-user-permissions-array-in-user-token/83024/4 "2022-12-21T16:11:33Z")

</div>


