I have a question about user roles. When I create roles and assign a role to a user, I expect to retrieve a list of users using ‘event.authorization.roles’ in PostLogin. However, the array is always empty (), even though other details like username and metadata are returned correctly.
Welcome to the Auth0 Community!
If you have assigned roles to a user via the Auth0 Dashboard, they should be present in the event.authorization.roles
parameter inside the PostLogin Action
.
I have just tested this on my end with an user who has assigned roles using the Real-Time Webtask Logs
extension available within the Auth0 and I was able to retrieve the user roles as seen below:
USER ROLES
ACTION CODE
exports.onExecutePostLogin = async (event, api) => {
console.log(event.authorization.roles)
}
LOG OUTPUT
If you have any other questions, let me know!
Kind Regards,
Nik
The problem is that despite assigning specific roles to the user, as shown in the figure above:
and I added the action trigger in PostLogin:
the results is an empty array for roles every time:
Hi again @badredine.haouari
That is quite weird. The roles should definitely be available through event.authorization.roles
as long as you have roles assigned through the dashboard.
I have used the same code you have posted inside the action and I was able to receive results in the console log and also the ID token of the user:
ID TOKEN
CONSOLE LOG

ACTION
Could you try creating a test app and user and let me know if the ID token contains the claims set by the action?
Kind Regards,
Nik