Created
December 29, 2020 06:53
-
-
Save dhavaln/ebfce9c61634b780db16985fdb3b2cfb to your computer and use it in GitHub Desktop.
Check for Domains and Emails before Cognito Signup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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