How to add "roles" to user via Rules and include in root attributes

Hey all,

I am using:

Currently - I have it configured so that any user that logs in will be given the role “user”.

The issue I am having is that I have a variety of roles that I want to configure with permissions etc.

The method above seems to only add a “roles” field to their app_metadata - it does not in fact add them to the user role that I created on the roles webpage.

How would I be able to implement this, so that it updates both the app_metadata and also the actual “roles” that I have created?

Secondly - is there a way to get app_metadata.roles (or the user role) to the root attributes, so that I can check what type of user they are before determining what content to show them on my app?

Currently to call this info I am user the PHP example with $userInfo[‘roles’].

Checkout this doc:

It shows how to access the roles you created for that user in the dashboard.

If you added the roles to the token like in the link above, then you could check that for their role and display content conditionally based on that.

Let me know if you have any questions :smile:

Hi,

Thanks for the response. To reiterate, the code I used above in the Rule “Set roles to a user” only sets app_metadata.roles - it does not set the roles of the user in the dashboard under the Roles section. How would I adjust the code in the link I sent to resolve this?

It’s linked in the doc.

Sample Use Cases: Rules with Authorization

Hey Dan thanks for the message again.

I don’t think I am explaining myself well enough. The above code seems to assume I have already assigned roles to a user in the dashboard.

What I want is to create a rule that assigns them certain roles, not that gets those details if they already have one.

For example, I want them to log in and get the “user” role assigned to them through a rule.

I don’t believe the above example does this, it seems to provide their role only if I set it first in the dashboard

Thanks for clarifying. Check this out:

That worked perfectly in conjunction with the previous link for my use case.

Thank you!

1 Like

Glad we got that one figured out!

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