# How to get user roles in non-react functions on client in spa?

**URL:** <https://community.auth0.com/t/how-to-get-user-roles-in-non-react-functions-on-client-in-spa/182173>\
**Category:** Get Help\
**Tags:** sdks-quickstarts, auth0-react\
**Created:** [February 14, 2025, 1:31pm UTC](https://community.auth0.com/t/how-to-get-user-roles-in-non-react-functions-on-client-in-spa/182173 "2025-02-14T13:31:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![skorphil](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/skorphil/32/71028_2.png) [@skorphil](https://community.auth0.com/u/skorphil)\
**Post date:** [February 14, 2025, 1:31pm UTC](https://community.auth0.com/t/how-to-get-user-roles-in-non-react-functions-on-client-in-spa/182173/1 "2025-02-14T13:31:05Z")

</div>

Task: I need to retrieve roles of the users in non-react functions on the client (SPA)

Context: For react components i use:

```auto
import { useAuth0 } from "@auth0/auth0-react";
const { user } =
    useAuth0();
  const roles = (user?.["mydomain"] as string[]) || undefined;

```

How can i achieve same thing in non-react functions? I thought maybe somehow extract instance of AuthService from and use it somehow?

---

<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:** [February 14, 2025, 8:34pm UTC](https://community.auth0.com/t/how-to-get-user-roles-in-non-react-functions-on-client-in-spa/182173/3 "2025-02-14T20:34:01Z")

</div>

Hi @skorphil,

Yes, this is possible. To retrieve the user roles in non-React functions, you can call the `getIdTokenClaims()` function inside a React component wrapped in `Auth0Provider`. This way, the token is decoded with its claims cached and can be accessed later in non-React functions.

Let me know if you have any questions.

Thanks,  
Rueben

---

<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:** [February 28, 2025, 8:34pm UTC](https://community.auth0.com/t/how-to-get-user-roles-in-non-react-functions-on-client-in-spa/182173/4 "2025-02-28T20:34:25Z")

</div>

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