Pre Signup action - Passwordless with Organizations

I am trying to setup Passworldless login with organizations and add a pre signup hook to validate the email domain against the organization to which the user is login. The problem is that there is no way of knowing the organization from inside the hook, even if it is send in authorizationParams. Any way to go around it?

Based on Passing custom parameters to pre-registration action from New Universal Login. I can see that it is not possible to pass custom parameters but I should at least be able to see the organization

const providerConfig = {
  domain: config.domain,
  clientId: config.clientId,
  onRedirectCallback,
  authorizationParams: {
    organization: "ORGANIZATION_ID",
    redirect_uri: window.location.origin,
    connection: "email",
    ...(config.audience ? { audience: config.audience } : null),
  },
};

ReactDOM.render(
  <Auth0Provider {...providerConfig}>
    <App />
  </Auth0Provider>,
  document.getElementById("root")
);

Hi @adrian_gd,

Welcome to the Auth0 Community!

Your observations are correct! It is currently not possible to determine the Organization name in a Pre User Registration Action.

As an alternative, I recommend using a Post-Login Action to check the user’s email domain against the Organization on their first login.

The code to do this would be something like the following:

exports.onExecutePostLogin = async (event, api) => {
  if (event.stats.logins_count === 1 && event.connection.strategy === "email"){ // First login and authenticating with Passwordless Email
    
    var userEmailDomain = event.user.email.split('@')[1].split('.')[0] // Get the user's email domain
    
    if(userEmailDomain === event.organization.name){
      // Your logic here
    }
  }
};

I hope this helps!

Please let me know if you have any questions or need further clarification.

Thanks,
Rueben

1 Like

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