Roles not coming back in User

I’m using the latest version of auth0-react

When using…

const { user } = useAuth0();

I see all my user data but Nothing to do with Roles.or Permissions.

I want to be able to create a route that only admins can see.

Hi @jodie,

The roles/permissions info will not be included in the ID Token by default. In order to include them, you can add a custom claim in a post-login action:

/**
 * @param {Event} event - Details about the user and the context in which they are logging in.
 * @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
 */
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://my-app.example.com';
  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
    api.accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
  }
}

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