How to allow user to choose role at sign up? [React, Serverless]

I’m trying to find out if it’s possible to allow a user to select their role on sign up, rather than giving them a default role. Additionally, I’d like the user also to be able to select the other role at a later time, after signing up.

This is the scenario:

  • User is given the option to select from Role A or Role B while signing up. They select Role A, sign up and log in, and are able to see some pages and page content that is only shown to Role A users.
  • Later, the user can edit their settings and also select Role B. Now they can see pages that are only shown to Role B users and also the earlier pages and content shown only for Role A users.

My set up is a serverless React app using the Auth0Provider context. Ideally, I’d like to be able to get an array of roles out of the user object from the useAuth0 hook, if possible.

Is there a recommended approach for this?

Thank you very much for the help.

Hi @c.ryberg,

Getting the user’s initial role could be done a couple of different ways. You could:

  • You could use a mandatory redirect rule. * I would look at this option first *

    • When a user signs up/logs in, you will check if they have any roles, if they don’t then redirect to a role selection page you create.
  • Set up additional fields on the signup page.

    • This will only work for database connection if you are using lock (no google or facebook support :frowning: )
  • Create a custom signup page.

    • This will likely take the most development.

Switching roles can be done in your app, they could make the request through a profile or settings page and your backend/API can make the update Auth0 management API.

Getting roles in the token is demonstrated in this example.

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