How to assign role to a user in app_metadata at signup?

I’m trying to figure out how should I assign a role to a user in app_metadata when the user registers.

My use case is as follows: I have 2 roles, A and B. I want to figure out a way to let the user choose when signing up if he/she wants to have role A or role B.
After signing up, the user should be assigned to either role A or role B.

I want to expose different functionality of my app (Angular6 with Django backend API) depending on the role of the user.

At the moment I’m using the universal login page for signing up/logging in users. Should I provide an extra parameter to the universal login page and then set up a custom rule, such that I assign the role based on this extra config parameter?

Or should I use custom fields for Lock when signing up? I understand this requires database signups, but I want Auth0 to host the login info.

I only want to modify the user’s app_metadata at signup , as I don’t want the user to be able to change roles later.

Thank you very much for your help.

Hey there @dnstanciu! Leveraging Rules should be able to help you apply different functionality depending on the user. I have referenced the Rules doc below for ease of use. Please let me know if you have any additional questions!

1 Like

Hi James! Thank you for replying. I’ve looked at the rules docs but I’m still not sure how to let the user choose the role they want on account creation.

Should I post an additional parameter containing the role and look that up in context.request.body? (as it’s done in this article)

Or should I send a custom query parameter to auth0’s hosted login page? (although this is discouraged…)

Again, the problem I’m having is finding a way to let the user choose which role they want at signup.

Thanks!

In the end, I sent a customer query parameter to auth0’s hosted login page:

auth0.authorize({ <my_parameter: "someValue" });

This is then accessed in a rule using context.request.query.<my_parameter>.

Thanks again for the help!

1 Like

Awesome @dnstanciu, I’m glad it all came together!

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