Payload has no roles in accessToken

I am having problems getting the roles of a user.

I have created the roles and associated users with them. Two Roles Admin and User and two users one for each role.

I also have created in the Login flow the code to get the roles:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = '';
  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
    api.accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);

I request the getAccessTokenSilently and the accessToken is received with the payload but the roles are not coming:

  "iss": "",
  "sub": "auth0|642335d4e1118da83ff192a5",
  "aud": [
  "iat": 1681297803,
  "exp": 1681384203,
  "azp": "OairsgbVMfSz5GNl6k0QuWXq4kmcmqPQ",
  "scope": "openid profile email"

What am I missing?

Best regards,

My CreateAuth0 is like:

export default createAuth0({
    domain: process.env.VUE_APP_AUTH0_DOMAIN,
    clientId: process.env.VUE_APP_AUTH0_CLIENT_ID,
    scope: process.env.VUE_APP_AUTH0_SCOPE,
    authorizationParams: {
        audience: process.env.VUE_APP_AUTH0_AUDIENCE,
        redirect_uri: process.env.VUE_APP_BASE_URL + '/' + process.env.VUE_APP_AUTH0_REDIRECT + '/'
    onRedirectCallback: appState => {
            appState && appState.targetUrl
                ? appState.targetUrl
                : window.location.pathname

And here are the images of the Auth0 console:

Hey there @pedro.sarmento!

Thanks for the detailed description and screenshots - The issue here is that you cannot use in your namespace. Please see the guidelines here:

Other than that, everything looks good - If you change your namespace you should be good to go :rocket:

Thank you!

Problem solved

1 Like

No problem, happy to help! Thanks for confirming :slight_smile:

1 Like

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