We are working on to migrate from Rules to action. We need sample code of Email domain verification to use in action.
Currently, we are using below code in Rules.
function emailDomainWhitelist(user, context, callback) {
// Access should only be granted to verified users.
if (!user.email || !user.email_verified) {
return callback(new UnauthorizedError('Access denied.'));
}
const whitelist = ['gmail.com']; //authorized domains
const userHasAccess = whitelist.some(function (domain) {
const emailSplit = user.email.split('@');
return emailSplit[emailSplit.length - 1].toLowerCase() === domain;
});
if (!userHasAccess) {
return callback(new UnauthorizedError('Access denied.'));
}
return callback(null, user, context);
}