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
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.