# Best practice for role-based or permission-based authorization in a React SPA

**URL:** <https://community.auth0.com/t/best-practice-for-role-based-or-permission-based-authorization-in-a-react-spa/194364>\
**Category:** Get Help\
**Tags:** configuration, application\
**Created:** [November 11, 2025, 11:44pm UTC](https://community.auth0.com/t/best-practice-for-role-based-or-permission-based-authorization-in-a-react-spa/194364 "2025-11-11T23:44:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ale.sassi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ale.sassi/32/70995_2.png) [@ale.sassi](https://community.auth0.com/u/ale.sassi)\
**Post date:** [November 11, 2025, 11:44pm UTC](https://community.auth0.com/t/best-practice-for-role-based-or-permission-based-authorization-in-a-react-spa/194364/1 "2025-11-11T23:44:04Z")

</div>

I’m using Auth0 with a React single-page application.  
I need to implement authorization logic at the frontend level — for example, hiding certain routes or UI elements depending on what the user is allowed to do (e.g., only admins can access an admin dashboard).  
I see a few possible approaches:  
Include user roles as a custom claim in the ID or access token via an Auth0 Post-Login Action (I’ve read that Auth0 provides this option). Then, check the roles in the React app.  
Instead of roles, rely on the permissions claim that Auth0 automatically adds to the access token when RBAC is enabled (“Add permissions in the Access Token” option).  
Dynamically retrieve roles or permissions from the Auth0 Management API (though I know this isn’t recommended directly from the browser).  
I’ve read that tokens generally shouldn’t expose too much authorization data, and I’m trying to understand what’s considered a best practice for SPAs.

For frontend-only route visibility (not API enforcement), should I rely on roles in the token (via a Post-Login Action), on permissions in the token (via RBAC), or is there a more secure/recommended way to handle client-side authorization in a React SPA using Auth0?

Thanks!

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [November 12, 2025, 2:15pm UTC](https://community.auth0.com/t/best-practice-for-role-based-or-permission-based-authorization-in-a-react-spa/194364/3 "2025-11-12T14:15:28Z")

</div>

Hi @ale.sassi

Welcome to the Auth0 Community!

Thank you for posting your question. Your best bet is to use the Auth0 RBAC inside the API setting, with the addition of adding the permission to the access token in the API RBAC setting. This way, users who have been assigned a specific role will automatically receive the permission during access token retrieval.

1. Here’s a guide on how to add permissions to API → [Add API Permissions](https://auth0.com/docs/get-started/apis/add-api-permissions)

2. Access Token validation → [Validate Access Tokens](https://auth0.com/docs/secure/tokens/access-tokens/validate-access-tokens)

3. Protecting a route with a claims check → [auth0-react/EXAMPLES.md at main · auth0/auth0-react · GitHub](https://github.com/auth0/auth0-react/blob/main/EXAMPLES.md?utm_source=chatgpt.com#protecting-a-route-with-a-claims-check)

> **[Sample Use Cases: Role-Based Access Control](https://auth0.com/docs/manage-users/access-control/sample-use-cases-role-based-access-control)**
>
> Learn how to implement roles-based authorization (RBAC) in different scenarios and explore how to use rules with RBAC.

> **[Auth0 Support Center](https://support.auth0.com/center/s/article/add-roles-and-permissions-to-the-id-token-using-actions?utm_source=chatgpt.com)**
>
> The Auth0 Support Center is your resource for product help. Explore articles, join community discussions, and submit support tickets to get the answers you need.

Thank you and let me know if you have additional questions  
Dawid

---

<div class="post-metadata">

**Author:** ![ale.sassi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ale.sassi/32/70995_2.png) [@ale.sassi](https://community.auth0.com/u/ale.sassi)\
**Post date:** [November 15, 2025, 4:59pm UTC](https://community.auth0.com/t/best-practice-for-role-based-or-permission-based-authorization-in-a-react-spa/194364/4 "2025-11-15T16:59:33Z")

</div>

Thanks for the previous answers. I’m mainly concerned with the _frontend_ side of RBAC.  
Right now, I already receive the user’s permissions in the access token, but I’m not sure what the best practice is for authorizing access to specific frontend routes.

For example: only an **admin** user should be able to visit a certain page in my React app.  
If the user’s **role** were present in the token, I could simply check it in the routing logic.  
However, since I already have **permissions** in the token, I could instead base my route protection on those permissions rather than on roles.

This is where my confusion started: when I enabled RBAC, I assumed Auth0 would automatically include the user’s role in the token. Later, I discovered that roles are _not_ included by default, and that you need a Post-Login Action to add them manually — and I also read recommendations saying that exposing roles in tokens is not ideal.

I hope this clarifies my doubts:  
**For frontend-only route visibility, should I rely on roles added via a Post-Login Action, or should I structure all authorization logic around the permissions already included in the token?**

Thanks!

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [November 18, 2025, 1:01pm UTC](https://community.auth0.com/t/best-practice-for-role-based-or-permission-based-authorization-in-a-react-spa/194364/5 "2025-11-18T13:01:36Z")

</div>

Hi @ale.sassi

I would advise structuring the authorization logic around the permissions already included in the token and using roles as the groups (how you assign capabilities) and permissions as capabilities (how you enforce access). This will also enable a granular approach to accessing the resources behind protected routes.

Lastly, please ensure to use the Authorization Code with PKCE as it’s currently the OAuth 2.0 standard for the SPAs → [Authorization Code Flow with Proof Key for Code Exchange (PKCE)](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow-with-pkce)

Thanks!  
Dawid

---

<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:** [December 2, 2025, 1:02pm UTC](https://community.auth0.com/t/best-practice-for-role-based-or-permission-based-authorization-in-a-react-spa/194364/6 "2025-12-02T13:02:08Z")

</div>

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