Hi everyone,
I’m currently facing an issue with Auth0 during the signup process using Universal Login with custom fields.
I’ve created a Pre-User Registration Action to validate and store the first and last name from the signup form, like this:
exports.onExecutePreUserRegistration = async (event, api) => {
if (!event.user.family_name || !event.user.given_name) {
if (!event.request.body['ulp-first-name'] || event.request.body['ulp-first-name'].trim() === "") {
api.access.deny("First name (given_name) is required", "Please provide your first name to complete the registration.");
return;
}
if (!event.request.body['ulp-last-name'] || event.request.body['ulp-last-name'].trim() === "") {
console.log("Last name (family_name) is not provided, proceeding with registration.");
}
api.user.setUserMetadata("given_name", event.request.body["ulp-first-name"] || "");
api.user.setUserMetadata("family_name", event.request.body["ulp-last-name"] || "");
}
};
The issue is:
When the user signs up, the
given_name
and family_name
fields are missing in the ID token and user object.
But if the user logs out and logs back in, those fields are suddenly available.
I’m assuming this is because they’re stored in user_metadata
during signup, and not reflected in the token immediately.
My question:
How can I make sure given_name
and family_name
are included in the ID token the very first time the user signs up (without needing a second login)?
Do I need to create a Post-Login Action to map user_metadata
into token claims manually? Or is there a more “Auth0-native” way to do this?
Thanks in advance for any help or recommendations!
Aditya