Getting First and Last name during signup

Hi,

I am after some help please. I am trying to get first and last name during the signup process using the new universal login experience via actions. Is this possible? If not, whats easiest way to achieve it?

exports.onExecutePreUserRegistration = async (event, api) => {
  // Check if the form has been submitted and data is present.
  if (event.forms?.data?.given_name && event.forms?.data?.family_name) {
    const { given_name, family_name } = event.forms.data;
    api.user.setUserMetadata("firstName", given_name);
    // Use the same key 'lastName' for consistency.
    api.user.setUserMetadata("lastName", family_name);
    return;
  }

  // Check if the names are already present from another source.
  if (!event.user.user_metadata?.given_name && !event.user.user_metadata?.family_name) {
    // Trigger a form to ask for the extra info.

    api.forms.requestData({
      title: "Tell us a bit about yourself",
      description: "Please provide your first and last name to complete your registration.",
      fields: [
        {
          key: "given_name",
          label: "First Name",
          type: "text",
          required: true,
        },
        {
          key: "family_name",
          label: "Last Name",
          type: "text",
          required: true,
        },
      ],
    });
  }
};

Hi @kurt.dunn

Welcome back to the Auth0 Community!

Regarding adding additional data to the user profile, there are 2 approaches that I would recommend:

  • Customize the partials for the signup prompt of your Universal Login in order to contain additional fields for First and Last name. There is a good example available in our documentation right here.
  • Render a form on an user’s first login in order to collect this data and add it to their profile. An example of such a form would be:

If you have any other questions, let me know!

Kind Regards,
Nik

Hi Nik,

Ive added the partial to the sign up form via the api as I need to capture this detail here and not later.

The trouble now is when i use Database > Try I can see the rendered partial as expected.

But when i login via my app the partials do not render.

Any ideas?