fix(api): add toLowerCase method to email (#38586)
This commit is contained in:
@ -3,6 +3,7 @@ module.exports = {
|
||||
require.resolve('babel-plugin-transform-function-bind'),
|
||||
require.resolve('@babel/plugin-proposal-class-properties'),
|
||||
require.resolve('@babel/plugin-proposal-object-rest-spread'),
|
||||
require.resolve('@babel/plugin-proposal-optional-chaining')
|
||||
],
|
||||
presets: [
|
||||
[
|
||||
|
@ -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'),
|
||||
|
30
api-server/common/models/User-Identity.test.js
Normal file
30
api-server/common/models/User-Identity.test.js
Normal file
@ -0,0 +1,30 @@
|
||||
/* global expect */
|
||||
import { ensureLowerCaseEmail } from './User-Identity';
|
||||
|
||||
test('returns lowercase email when one exists', () => {
|
||||
const profile = {
|
||||
id: 2,
|
||||
emails: [{ value: 'Example@Mail.com', name: 'John Doe' }]
|
||||
};
|
||||
expect(ensureLowerCaseEmail(profile)).toBe('example@mail.com');
|
||||
});
|
||||
|
||||
test('returns empty string when value is undefined', () => {
|
||||
const profile = {
|
||||
id: 4,
|
||||
emails: []
|
||||
};
|
||||
expect(ensureLowerCaseEmail(profile)).toBe('');
|
||||
});
|
||||
|
||||
test('returns empty string when emails is undefined', () => {
|
||||
const profile = {
|
||||
id: 5
|
||||
};
|
||||
expect(ensureLowerCaseEmail(profile)).toBe('');
|
||||
});
|
||||
|
||||
test('returns empty string when profile is undefined', () => {
|
||||
let profile;
|
||||
expect(ensureLowerCaseEmail(profile)).toBe('');
|
||||
});
|
35
api-server/package-lock.json
generated
35
api-server/package-lock.json
generated
@ -705,6 +705,24 @@
|
||||
"@babel/plugin-syntax-optional-catch-binding": "^7.2.0"
|
||||
}
|
||||
},
|
||||
"@babel/plugin-proposal-optional-chaining": {
|
||||
"version": "7.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.9.0.tgz",
|
||||
"integrity": "sha512-NDn5tu3tcv4W30jNhmc2hyD5c56G6cXx4TesJubhxrJeCvuuMpttxr0OnNCqbZGhFjLrg+NIhxxC+BK5F6yS3w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/helper-plugin-utils": "^7.8.3",
|
||||
"@babel/plugin-syntax-optional-chaining": "^7.8.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/helper-plugin-utils": {
|
||||
"version": "7.8.3",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.8.3.tgz",
|
||||
"integrity": "sha512-j+fq49Xds2smCUNYmEHF9kGNkhbet6yVIBp4e6oeQpH1RUs/Ir06xUKzDjDkGcaaokPiTNs2JBWHjaE4csUkZQ==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"@babel/plugin-proposal-unicode-property-regex": {
|
||||
"version": "7.6.2",
|
||||
"resolved": "https://registry.npmjs.org/@babel/plugin-proposal-unicode-property-regex/-/plugin-proposal-unicode-property-regex-7.6.2.tgz",
|
||||
@ -761,6 +779,23 @@
|
||||
"@babel/helper-plugin-utils": "^7.0.0"
|
||||
}
|
||||
},
|
||||
"@babel/plugin-syntax-optional-chaining": {
|
||||
"version": "7.8.3",
|
||||
"resolved": "https://registry.npmjs.org/@babel/plugin-syntax-optional-chaining/-/plugin-syntax-optional-chaining-7.8.3.tgz",
|
||||
"integrity": "sha512-KoK9ErH1MBlCPxV0VANkXW2/dw4vlbGDrFgz8bmUsBGYkFRcbRwMh6cIJubdPrkxRwuGdtCk0v/wPTKbQgBjkg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/helper-plugin-utils": "^7.8.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/helper-plugin-utils": {
|
||||
"version": "7.8.3",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.8.3.tgz",
|
||||
"integrity": "sha512-j+fq49Xds2smCUNYmEHF9kGNkhbet6yVIBp4e6oeQpH1RUs/Ir06xUKzDjDkGcaaokPiTNs2JBWHjaE4csUkZQ==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"@babel/plugin-transform-arrow-functions": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.2.0.tgz",
|
||||
|
@ -73,6 +73,7 @@
|
||||
"@babel/node": "^7.6.3",
|
||||
"@babel/plugin-proposal-class-properties": "^7.5.5",
|
||||
"@babel/plugin-proposal-object-rest-spread": "^7.6.2",
|
||||
"@babel/plugin-proposal-optional-chaining": "^7.9.0",
|
||||
"@babel/preset-env": "^7.6.3",
|
||||
"@babel/register": "^7.9.0",
|
||||
"adler32": "~0.1.7",
|
||||
|
Reference in New Issue
Block a user