Using api.user.setAppMetadata() in Pre Registration Action for Passwordless flow

Hello, I’m trying to add some data to a user’s app_metadata in a pre-registration action for a passwordless flow. However, when running something like this in my action:

exports.onExecutePreUserRegistration = async (event, api) => {
  api.user.setAppMetadata('foo', 'bar');
};

After the user is created I don’t see the {'foo': 'bar'} data in the user’s app_metadata. I’m also adding some logging to the Action which I do see running with no errors using the Real-Time webtask logs.

I did see this post from June 2021 that suggests this is a bug, wondering if this was just never fixed, or if I’m missing something on my end. Thanks for your time!

Hi @cmaciel,

Welcome to the Auth0 Community!

I understand that you have not been able to set the user_metadata for Passwordless Users in a Pre-User Registration Flow.

After testing this myself, I noticed the same observations as you where updating the user_metadata does not persist in the user profile. More interestingly, when using the Realtime Webtask Logs extension to print the event.user property, the user_metadata shows the updated values but ignores updating them in the user profile.

Moreover, after checking with our Engineering teams, I can confirm that this is a known bug and has been moved into our product backlog to be addressed. However, I am unable to provide an ETA as to when this will be fixed.

I hope this answers your questions.

Please reach out if you have additional questions.

Thank you.

Hi @rueben.tiow,

Thanks for the investigation. Do you know if instead of actions, I can use either Rules or Hooks to update a user’s user_metadata in a pre-user registration flow since Actions is broken? Or are there any work arounds for this bug?

Thanks!

Hi @cmaciel,

Thank you for your response!

Unfortunately, it will not be possible to workaround this issue at the moment using either Rules or Hooks since behind the scenes, they function the same as Actions.

However, I would suggest a workaround using a Post-Login Action and checking if the user satisfies a condition that allows you to set the user_metadata on the first login.

For example:

exports.onExecutePostLogin = async (event, api) => {
  if(!event.user.user_metadata.setMetadata){
    //set your other user_metadata here
    api.user.setUserMetadata("setMetadata", true)
}

I hope this helps!

Please let me know if there’s anything else I can do to help.

Thank you.