I want to assign “admin” role the new user who signup through auth0 dashboard. All users who will be created by admin, will be assigned roles by admin to them. So when the users created by admin, login through dashboard, they should still have the roles assigned by admin and not the role “admin” itself.
So in short, only the users who signup through dashboard should have “admin” role and rest of users role is decided by admin.
Please suggest how this default role assignment can be done during signup.
I recommend using the Management API’s Assign roles to a user endpoint inside an Auth0 Pre-registration Action script to assign your users to the “admin” role.
Thank you for the reply. But I am getting error message about ‘user_id’ not being present in event.user object. What am I missing here? Is it because the user_id is not present before the registration?
Property ‘user_id’ does not exist on type ‘{ username?: string | undefined; email?: string | undefined; app_metadata?: AppMetadata0 | undefined; user_metadata?: UserMetadata0 | undefined; name?: string | undefined; … 4 more …; picture?: string | undefined; }’.
Thanks for the modifications. It does add roles to user. But it assigns role to both users registered through ‘auth0 login page’ and users created by admin. I wanted to achieve the former only.
I guess the best way for me is to create some button in frontend, say, “get paid account” and when user actually clicks it, I can internally call management api to assign the Admin role. And of-course the user can get paid account only if he pays for it.
It may be possible to do this if the admin creates these users with some user_metadata value, for example "created_by_admin": true, and using it in the Action to check if this condition is false.