Use Actions to Validate and Store End-user Data Gathered By Signup Prompt Customizations

You can use Signup Prompt Customization along with the pre-user-registration trigger to add end-user supplied data (like a user's phone number or location) from the signup prompt to user_metadata. Optionally, you can validate this data and show a validation error in the prompt.

Prerequisites

Add A Field To The Signup Prompt

Use the Management API to insert a custom field into a prompt using one of the Entry Points. This example adds the following content to the ulp-container-form-content-start insertion point:

<div class="ulp-field">
  <label for="first-name">First Name</label>
  <input type="text" name="ulp-first-name" id="first-name">
</div>

Was this helpful?

/

The result is a First Name section in the signup prompt:

Create An Action In The Pre-User Registration Trigger

You can build a custom pre-user registration action by going to Actions > Library > Build Custom.

Inside the code editor, update the onExecutePreUserRegistration handler:

exports.onExecutePreUserRegistration = async (event, api) => {
  const firstName = event.request.body['ulp-first-name'];
  api.user.setUserMetadata("firstName", firstName);
};

Was this helpful?

/

Optionally, you can validate the user input and send a validation error by calling the api.validation.error method, then deploy the action:

exports.onExecutePreUserRegistration = async (event, api) => {
  const firstName = event.request.body['ulp-first-name'];
  if(!firstName) {
    api.validation.error("invalid_payload", "Missing first name");
    return;
  }

  api.user.setUserMetadata("firstName", firstName);
};

Was this helpful?

/

Add The Action To The Flow

Navigate to Actions > Flows > Pre User Registration > Add Action > Custom, then drag and drop your new action into the registration flow and select Apply.

Test The Action

Sign up for an account in your test flow and leave the First Name field blank. You will see an error on submit:

After you enter a name in the First Name field, you are able to submit successfully:

Verify That The Data Was Saved On user_metadata

Navigate to User Management > Users, then confirm the data has been saved by viewing the Details tab: