# Pre-User Registration, how to assign default role?

**URL:** <https://community.auth0.com/t/pre-user-registration-how-to-assign-default-role/45767>\
**Category:** Get Help\
**Created:** [July 3, 2020, 9:44pm UTC](https://community.auth0.com/t/pre-user-registration-how-to-assign-default-role/45767 "2020-07-03T21:44:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alexab/32/13403_2.png) [@alexab](https://community.auth0.com/u/alexab)\
**Post date:** [July 3, 2020, 9:44pm UTC](https://community.auth0.com/t/pre-user-registration-how-to-assign-default-role/45767/1 "2020-07-03T21:44:19Z")

</div>

I am developing a solution, where I would like to set a default user role, on user registration.

**Sub question 1)** Can this be done directly in the hook?  
With Auth0 rules, our team used to do something like this:

```auto
var ManagementClient = require('auth0@2.17.0').ManagementClient;
var management = new ManagementClient({
    token: auth0.accessToken,
    domain: auth0.domain,
});
management.assignRolestoUser( //etc.

```

**Sub question 2)** If I POST our own application server, and set the role their using the auth0 management API, will the user have the role assigned on the first login? If I remember correctly, this is something Auth0 advised against when writing rules.

@konrad.sopala can you with this one? Thanks once again 🙌🏾

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 7, 2020, 1:04pm UTC](https://community.auth0.com/t/pre-user-registration-how-to-assign-default-role/45767/2 "2020-07-07T13:04:17Z")

</div>

Hey!

So starting from the question 2. Yep you’re correct this is something that we advise against doing.

When it comes to the first question. Not sure why you thought about pre-user registration hook as you should be using post-user registration hook here.

---

<div class="post-metadata">

**Author:** ![alexab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alexab/32/13403_2.png) [@alexab](https://community.auth0.com/u/alexab)\
**Post date:** [July 7, 2020, 1:12pm UTC](https://community.auth0.com/t/pre-user-registration-how-to-assign-default-role/45767/4 "2020-07-07T13:12:34Z")

</div>

Ok - I should use the post-user registration hook. By my question is still un-answered 🤔

How do I actually assign the default role? Do I access the ManagementClient - like in rules?

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 8, 2020, 2:06pm UTC](https://community.auth0.com/t/pre-user-registration-how-to-assign-default-role/45767/5 "2020-07-08T14:06:24Z")

</div>

Yep you’re pretty much using the Management API for that:

> **[Assign Roles to Users](https://auth0.com/docs/manage-users/access-control/configure-core-rbac/rbac-users/assign-roles-to-users)**
>
> Learn how to assign roles to a user using the Auth0 Dashboard or the Management API.

---

<div class="post-metadata">

**Author:** ![alexab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alexab/32/13403_2.png) [@alexab](https://community.auth0.com/u/alexab)\
**Post date:** [July 8, 2020, 2:13pm UTC](https://community.auth0.com/t/pre-user-registration-how-to-assign-default-role/45767/6 "2020-07-08T14:13:17Z")

</div>

Ok, and I get the management client like this?

```auto
var ManagementClient = require('auth0@2.17.0').ManagementClient;

```
