Skip to content

Instantly share code, notes, and snippets.

@dhavaln
Created December 29, 2020 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhavaln/ebfce9c61634b780db16985fdb3b2cfb to your computer and use it in GitHub Desktop.
Save dhavaln/ebfce9c61634b780db16985fdb3b2cfb to your computer and use it in GitHub Desktop.
Check for Domains and Emails before Cognito Signup
const whitelistedDomains = process.env.WHITE_LISTED_DOMAINS.split(',');
const whitelistedEmails = process.env.WHITE_LISTED_EMAIL.split(',');
exports.handler = async (event, context, callback) => {
console.log('Validate signup request', event);
console.log('wd', whitelistedDomains)
console.log('we', whitelistedEmails)
// 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;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment