Allow only Organization and Whitelisted users to Signup
We are building an enterprise document management system. So we only want to allow only users who belong to our organization or whitelisted emails.

const whitelistedDomains = ['appgambit.com'];
const whitelistedEmails = [];
exports.handler = async (event, context, callback) => {
// Split the email address so we can compare domains
const userEmail = event.request.userAttributes.email;
const userDomain = userEmail.split("@")[1];
console.log(`Validating domain ${userDomain} and email ${userEmail}`);
if(whitelistedEmails.indexOf(userEmail) < 0){
if (whitelistedDomains.indexOf(userDomain) < 0) {
throw new Error('EMAIL_DOMAIN_ERR')
}
}
// Return to Amazon Cognito
return event;
};

Last updated