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: