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,
},
],
});
}
};