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

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

Context: For react components i use:

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?

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