I’m trying to collect and store given_name and family_name on the sign-up screen. My configuration is below and successfully causes the fields to show:
However, when a user is created, the data is saved in the user_metadata area instead of the root, which I have clearly specified according to the docs (Lock Configuration Options). What am I doing wrong?
If you want to save the value of the attribute in the root of your profile, use storage: 'root' . Only a subset of values can be stored this way. The list of attributes that can be added to your root profile is here. By default, every additional sign up field is stored inside the user_metadata object.
Been battling this for weeks, this is what I’ve come up with:
additionalSignUpFields will always store in the user_metadata, even if the name of the field matches a standardised root claim.
You CAN add these claims in a Post-Registration Action, using something like the example below, but the Post-Registration Actions are run asynchonously - so you have zero guarantee that the call to the management API will complete before the auth server redirects you back to your app.
A Pre-Registration Action runs synchronously but does not allow you to modify the root user claims, only metadata. You also cannot use the method above because there is no user stored at this stage (you have no ID).
You can create a custom login form that does allow you to store whatever root fields you want at registration, but you have to use a custom template, which loses a lot of the power of Universal/Lock. Things like adding social login and MFA become more complex to add.
You could use additionalSignUpFields, add the custom fields to the metadata, add the metadata to the idToken via a Post-Login Action, then in your app collapse all the profile info down to one flat object for local use
@karen1 (gonna tag @konrad.sopala too as he’s a forum legend) there is a hell of a lot of people on the forum begging for an easy solution to this, for quite a while now. It is such a standard thing to ask for Given & Family Name in a signup form. Several solutions:
Make Post-Registration Hook synchronous.
Parse additionalSignUpFields for root claims and add only those to the root profile.
Add another option to the Lock config eg: rootSignUpFields that only allows things like name, DOB, etc.
Allow editing of the user object (beyond metadata) in a Pre-Registration Action.
But we really do need a solution. The point of the service is to simplify authentication and signup - if we have to backflip through flaming hoops to add first & last name to a user at registration then it’s kinda defeating the purpose…