Accessing users role post-login

Hi @RagnarSmari

Welcome to the Auth0 community!

How are you setting the roles in an action? You would assign the roles as such:

exports.onExecutePostLogin = async (event, api) => {

 api.idToken.setCustomClaim("https://randomtest.org/roles", event.authorization.roles)

}

By any chance, do the naming convention for the namespace when setting the custom claims using a PostLogin Action go against our restrictions mentioned in this documentation?

Otherwise, could you try assigning the roles like this:

  const session = getSession(req, res);
  
  console.log(session?.user['{{YOUR_NAMESPACE}}']

Also, session.user in this case should contain the custom claims you have set using the PostLogin Action.

Alternatively, you can try to retrieve this data using the useUser() hook mentioned in the Github Documentation.

Let me know if you have any other questions or if the solutions above were not helpful!

Kind Regards,
Nik