Event.user.user_id empty on passwordless Post User Registration hook

/**
* Handler that will be called during the execution of a PostUserRegistration flow.
*
* @param {Event} event - Details about the context and user that has registered.
*/
exports.onExecutePostUserRegistration = async (event) => {

  const { MGMT_SECRET, MGMT_DOMAIN, MGMT_CLIENT_ID } = event.secrets;
  const auth0 = require('auth0');
  var managementClient = new auth0.ManagementClient({
    domain: MGMT_DOMAIN,
    clientId: MGMT_CLIENT_ID,
    clientSecret: MGMT_SECRET})

  if (roles.length === 0 && event.user.email && event.user.email.endsWith("@cooper-sheldon.com")) {
    await managementClient.assignRolestoUser({id: event.user.user_id}, {roles: ['rol_sheldon']}) 
  }
};

If you try using this postHook with passwordless users the userID is not present and you are not able to assign them a role. However when I inspect the users in the console afterwards, the user is clearly there.
Can I somehow derive the user_id from the other data present in the event? OR how can I assign a role to a passwordless user from a specific domain?
I have just found this:

The Post-User Registration extensibility point is available for database connections. To learn more, see Database Connections.

This is supremely misleading and confusing as hell. For each of the flows I use I am forced to find custom / different solutions despite the fact they all have the same side effect → user with an id in my display panel. Is there any reason why the hooks are not triggered for users coming from socials or why the user_id is missing for passwordless users?


On a side note I don’t think I should be using domain as the guiding principle, but the question remains. How to do it, please refrain from questioning the approach - assume we have a way of checking if you’re not spoofing it.

Hey there!

As this topic is related to Rules - Hooks - Actions and Rules & Hooks are being deprecated soon I’m excited to let you know about our next Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

Learn more here!