Ability to Prompt Users for First and Last Name when Using the New Universal Login Experience Signup Flow
Last Updated:
Overview
This article explains whether it is possible to prompt users for the first and last names when using the New Universal Login Experience signup flow. These fields should not be empty and be stored in the user's user metadata.
Applies To
- New Universal Login
- Signup
Solution
PUT api/v2/prompts/signup/partials
{
"signup": {
"form-content-start": "<script>function validateName(element, formSubmitted) {if (!formSubmitted) {return true;}return element.value.length > 0;}</script><div class='ulp-field'><label for='first-name'>First Name</label><input type='text' name='ulp-first-name' id='first-name'><div class='ulp-error-info' data-ulp-validation-function='validateName' data-ulp-validation-event-listeners='blur,change,input,focus'>First Name is Required</div></div><div class='ulp-field'><label for='last-name'>Last Name</label><input type='text' name='ulp-last-name' id='last-name'><div class='ulp-error-info' data-ulp-validation-function='validateName' data-ulp-validation-event-listeners='blur,change,input,focus'>Last Name is Required</div></div>"
}
}
Updating the user profile needs a custom Pre-User registration Action. Here is a sample of how to store these fields in the user's user metadata;
exports.onExecutePreUserRegistration = async (event, api) => {
const firstName = event.request.body['ulp-first-name'];
const lastName = event.request.body['ulp-last-name'];
if(!firstName) {
api.validation.error("invalid_payload", "Missing Name");
return;
}
if(!lastName) {
api.validation.error("invalid_payload", "Missing Last Name");
return;
}
api.user.setUserMetadata("firstName", firstName);
api.user.setUserMetadata("lastName", lastName);
};