PreUserRegistration Action (using Passwordless) not setting user metadata


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:

exports.onExecutePreUserRegistration = async (event, api) => {
api.user.setUserMetadata(“some_field”, “some_value”);

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.

According to this post setAppMetadata during Pre-User-Registration using passwordless connections there seems to be a bug with Passwordless and Pre User Registration.

Is there any work around for my scenario?

Thanks in advance.

Hi @norberto,

Welcome to the Auth0 Community!

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.

Thank you.

Tanks for the reply @rueben.tiow

I’ll try that out

1 Like

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?

Hi @norberto,

Thank you for your response.

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.");

Please let me know how this works for you.

Thank you.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.