Hi, I have a few actions post login. But one of those actions it’s actually calling a form to add some user meta data.
For that one I’m using this code:
But it doesn’t work when it’s the first time the user logs in (when the form renders) if the user already logged in and has its meda data complete then the form it’s not rendering and in that case the token it’s adding the claim.
I already tried many different approaches but none of them are working
Yes, I have separate actions. Each of them have the code onExecutePostLogin.
First action is rendering the form if the user meta data it’s missing
Second action is setting the role if the user doesn’t have any role assigned
Third one issues the access token with the role
But as I mentioned, it issues the token with the role only when the form is not rendering.
I’m not storing the roles in the user_metadata.
I already checked the logs but I didn’t find any issue.
I did some debug and looks like the event.authorization.roles it’s not updating or it may take sometime?
Could be that because it’s a new user and the event object it’s the same for all the actions? So even that I’m adding the role in an action before the action that issues the token the event object already generated it’s not getting updated.
Beacuse when I console.log event.authorization.roles gives me 0
Yes, that’s correct. The event.authorization.roles only returns the roles assigned to the user before the initial login event. This is why you were not able to append the role as a custom claim until subsequent logins.
In this case, I recommend combining your second and third actions as one. This way, you can assign the role to the user and append it as a custom claim at the same time.
To get the role name, you could use the Management API to request the current role name or hardcode it as a variable. (Reference: RolesManager | auth0)