I am running passwordless and using pre user registration to try to add user metadata before the account is created. I’d like this to happen only once, when the user does “sign up”. I’m trying this:
This doesn’t seem to be triggering at all. I have also tried to add key/values to app metadata with api.user.setAppMetadata with no luck. I have checked the user profile and the user_metadata and app_metadata sections are empty.
I understand you encountered issues with the Pre-User Registration Action with Passwordless, specifically with not setting the user_metadata.
After my investigation, I found that this is a known issue and has already been reported to our Engineers. It has been moved to our backlog as an item to be addressed. However, I do not have an exact ETA as to when this will be fixed.
You could consider using the Management API Update a user endpoint to set the user_metadata values.
Alternatively, there is the option to use a Post-Login Action. Given that a user automatically logs in after signing up, you could leverage a Post-Login Action to set the user’s user_metadata.
If you prefer to have the Action execute once, you could include a conditional check to see if the user_metadata has been set. This way, you can guarantee execution exactly once.
For example:
exports.onExecutePostLogin = async (event, api) => {
if (!event.user.app_metadata.action_completed) {
// set user_metadata here
api.user.setAppMetadata("action_completed", true);
}
};
Hoped this helps!
Please do not hesitate to reach out if you have any further questions.
Just one more question. What I specifically want is to customize the email confirmation template that produces the email that gets to the end user with the passwrordless signup. I would like to add something like “Welcome John Doe, blablabla”, adding the name of the user to it (which comes from a form on my website). That’s why I was thinking on using the Pre Signup Action trigger.
Now, if I use the Post Login trigger instead, it seems like that would trigger too late, after the signup confirmation email for first time users is already delivered. Am I right?
And in that case, is there any way (other than using user_metadata) I could customize that confirmation email for passwordless signup to add the name of the user?
Yes, that is correct. However, to pile on to the solution, you could include a Force Email Verification Post-Login Action to disrupt the signup flow. This way, first-time users cannot continue access until they have verified their email address.
exports.onExecutePostLogin = async (event, api) => {
if (!event.user.email_verified) {
api.access.deny("Please verify your email before logging in.");
}
};