Is there any way to pass custom fields with passwordless flow in order to populate a user profile? i.e. If my sign up screen allows user to input their name and birthday, can I have that information passed through Auth0’s passwordless API? We want to be able to store that extra information during passwordless sign up. Thanks!
Hi @juliachxng
Thank you for reaching out to us!
After doing some research on this matter, it appears that data captured from a prompt in a Passwordless signup flow is only available in the Post Login Action trigger, and will not populate the Pre-User Registration trigger. This is important, as it would seem natural to us the Pre-User Registration Trigger to capture user data before the user creation, but since users are automatically logged in after a successful Passwordless sign-up, the Post-Login Action can be triggered to update the user’s profile with the desired information. This is outlined in our documentation on how to Customize Signup and Login Prompts.
To implement the correct logic, you can rely on the event.stats.logins_count property exposed in the Post Login Action which if it returns " 1 " it indicates that the user has just signed up. Once done, you can store your custom information on the user’s app_metadata, something similar to the following:
exports.onExecutePostLogin = async (event, api) => {
if (event.stats.logins_count === 1) {
api.user.setUserMetadata("name", "USER_NAME"); // Replace with the actual name
api.user.setUserMetadata("birthday", "USER_BIRTHDAY"); // Replace with the actual birthday
}
};
Hope this helped you achieve your desired flow! Please don’t hesitate to reach out to us for any other issues or requests.
Have a great one!
Gerald
Thanks @gerald.czifra !
This is what I did in my Post Login Actions and it works for updating the root profile fields. However, after a while those fields end up showing “undefined undefined” in the Auth0 user profile. Why is that happening?
// Also promote to root profile fields
const { ManagementClient } = require('auth0');
// Set secrets here
// ...
await management.users.update(event.user.user_id, {
given_name,
family_name,
name: `${given_name} ${family_name}`,
});