fix(api): add toLowerCase method to email (#38586)

This commit is contained in:
Shaun Hamilton
2020-04-24 11:53:29 +01:00
committed by GitHub
parent ce82ec9647
commit b1ea426f51
5 changed files with 75 additions and 4 deletions

View File

@@ -8,6 +8,12 @@ import { wrapHandledError } from '../../server/utils/create-handled-error.js';
// const log = debug('fcc:models:userIdent');
export function ensureLowerCaseEmail(profile) {
return typeof profile?.emails?.[0]?.value === 'string'
? profile.emails[0].value.toLowerCase()
: '';
}
export default function(UserIdent) {
UserIdent.on('dataSourceAttached', () => {
UserIdent.findOne$ = observeMethod(UserIdent, 'findOne');
@@ -41,10 +47,8 @@ export default function(UserIdent) {
include: 'user'
};
// get the email from the auth0 (its expected from social providers)
const email =
profile && profile.emails && profile.emails[0]
? profile.emails[0].value
: '';
const email = ensureLowerCaseEmail(profile);
if (!isEmail('' + email)) {
throw wrapHandledError(
new Error('invalid or empty email received from auth0'),