Pre-User Registration, how to assign default role?

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:

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 :raised_hands:t5:


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.

1 Like

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

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

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

Ok, and I get the management client like this?

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