How to set user meta data if the user use passwordless in flows

I want to set metadata if users use passwordless on the signIn only,
in the documentation says api.user.authentication not found

exports.onExecutePreUserRegistration = async (event, api) => {
        if (event.connection.name != "email")
            api.user.setUserMetadata("role", "passwordless ")
       else
            api.user.setUserMetadata("role", "not passwordless ")

};

Hi @huthefa.alfararjeh,

Thanks for reaching out to the Auth0 Community!

I understand you have issues using a Pre-User-Registration Action to add custom user_metadata to the user’s profile.

Firstly, I have gone ahead and tested this Action, and there appears to be a bug with using a Pre-User Registration Action with Passwordless connections even though it is supposed to work, as described in our Extensibility Points doc. Because of that, I’ll be reporting this to our Engineering team to resolve this issue.

In the meantime, you could work around this problem by using a Post-Login Action script. Because users are logged in immediately after signing up, this script will always trigger and won’t impact the login flow. I have tested this myself and can confirm that you’ll be able to set the user’s user_metadata.

Lastly, I want to point out that you have the wrong operator with the if-condition in your script. Your current if-condition checks whether the connection name is not equal to "email" then sets the user’s role as "passwordless" but this is semantically incorrect. Instead, you’ll need to set the user’s role as "passwordless" when the connection name does equal "email". Therefore, you’ll need to do something like the following:

exports.onExecutePostLogin = async (event, api) => {
  if (event.connection.name === "email"){
    api.user.setUserMetadata("role", "passwordless ")
  } 
  else {
    api.user.setUserMetadata("role", "not passwordless ")
  }
};

Please let me know if you have any further questions. I’d be happy to help.

Thank you.

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