Created
January 22, 2020 06:16
-
-
Save hisashiyamaguchi/77379753ebf6f4c4ca45a55e419ba886 to your computer and use it in GitHub Desktop.
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
// eslint-disable-next-line no-unused-vars | |
function deDupeEmail(user, context, callback) { | |
// Set app_metadata to empty object if it has not been set | |
user.app_metadata = user.app_metadata || {}; | |
const email = user.email || ''; | |
if (context.clientName === 'Duplicates0') { | |
context.idToken['https://duplicate.email/duplicate_email'] = user.app_metadata.duplicate_email; | |
callback(null, user, context); | |
return; | |
} | |
function shouldTriggerEmailDeDupe() { | |
// User has already been processed / verified their email | |
if (user.email_verified) return false; | |
// User is flagged as duplicated but has no completed de-duplication process | |
if (user.app_metadata.duplicate_email) return true; | |
// User email was detected by custom database script as being duplicate | |
return email.includes('@duplicate.email'); | |
} | |
if (shouldTriggerEmailDeDupe()) { | |
// Redirect to the Deduplicate App | |
context.redirect = { | |
url: `https://auth0japan.ddup-emails.accounts.travel0.net?t=${Date.now()}` | |
}; | |
} | |
callback(null, user, context); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment