We are in the process of migrating from another user database and have a custom database setup for this purpose. The login script there defines some user fields that don’t seem to be available to set from a hook script.
So, how do I set user fields outside app_metadata and user_metadata from a pre registration hook script?
I tried this:
var body = // Add user to old system and get data from there.
response.user.user_id = 'OldSystem|' + body.UserId;
response.user.nickname = body.FullName;
response.user.username = body.UserName;
response.user.given_name = body.FirstName;
response.user.family_name = body.LastName;
But none of these fields actually get set in the resulting Auth0 user object. The field nickname seems to be assigned the part before @ in the new user’s e-mail address.
The hook script does assign some app_metadata fields, which do get stored properly in Auth0’s new user object.
Is there any way to set those fields from the hook script?
As a last resort, would it be possible to add also a post registration hook script and let that set those Auth0 user fields? In that case, hos would such a script do that?
I should add that some apps still use the old system for user auth, so we need all new user registrations to be made to both Auth0 and the old system. That’s why the pre registration hook script saves the new user to the old system. It also retrieves the old-system user id and saves it to Auth0, so applications can login via Auth0 but be able to make API calls to the old system using that old-system user id to identify the user to the old system.
It does seem somewhat odd that the custom database login script and the pre reg hook script has different “access” to non-metadata parts of the Auth0 user object.
After talking with a senior engineer on this front @aneacsu_c and @krilbe, can you share your current pre-registration hook so we can take a look at the code you are working with? We also wanted to ask if the overall goal is to set root attributes? We have documentation on that front below that may help shed some light on how to accomplish that.
If by chance you are looking to migrate from a legacy system and import the data, you can leverage an automatic migration through custom scripts like described below.
Please let me know if this helps you in your pursuits or if you have any questions, thanks!
Here I am experiencing the same issue with the persistence after pre-registration hook.
Looks like user_metadata keys added to the hook’s response are not available after (from a rule or on the user in general).
On the hook I get a result with the user.user_metadata expected keys and valuse. I am validating it both from the hook webex tester as shown:
Just PMed you with the tenant
Also for easier reproduce, I removed all the logic from the hook and left only:
Promise.resolve then response.user.user_metadata = { name: ‘test’ }
You can still see that the webcode simulator shows a response with the user_metadata but it is not shown when checking the user profile
My bad, I was playing around and persisted metadata from a rule. Until you will answer I will freeze my activity on the platform.
From rules it works well, but not from the hook
Here is a video where you can see it better:
I have narrowed this down a bit. I can get everything working fine with a normal db connection, but it will not work with my passwordless sms connection. I am starting to think this is a bug and not a misconfig. Thanks for your patience on this.