Set role on sign-up that doesn't change

I have a Next js application with different types of user roles.
I’m trying to set up a role for a user on sign-up. I’m able to achieve that by using rules, but when I login using those credentials from the other role’s login, the role of that user gets updated.
Is there a way to prevent the role from being updated ?

Hi @pranjalbatra22,

Welcome to the Auth0 Community!

I understand you’d like to set the user’s role during sign-up.

In this scenario, I recommend using an Pre-User-Registration Action to set the user’s roles.

From doing so, your users will be assigned a role when they sign up but not when they log in.

Please let me know how this works for you.

Thank you.

2 Likes

Hi @rueben.tiow

Thanks for your response. This seems really helpful. I’m able to set the app metadata for the user but unable to set the role from the action. I searched around a lot but nothing worked. Could you please provide me with a sample code snippet to set the user’s role ?

1 Like

Hi @pranjalbatra22,

Thank you for your response.

In this case, you will also need to use the Management API v2 in Actions to assign the roles to a user.

See this How can I use the Management API in Actions? FAQ for details.

Please let me know if there’s anything else I can do to help.

Thanks!

1 Like

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