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?
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.