diff --git a/data-serving/scripts/setup-db/migrations/20211119121032-additional-user-indexes.js b/data-serving/scripts/setup-db/migrations/20211119121032-additional-user-indexes.js index 1658ef992..514708f24 100644 --- a/data-serving/scripts/setup-db/migrations/20211119121032-additional-user-indexes.js +++ b/data-serving/scripts/setup-db/migrations/20211119121032-additional-user-indexes.js @@ -1,24 +1,24 @@ const indexes = [ - { - name: 'googleID', - key: { - googleID: 1, + { + name: 'googleID', + key: { + googleID: 1, + }, }, - }, -] +]; module.exports = { - async up(db, client) { - await db.command({ - createIndexes: 'users', - indexes: indexes, - }); - }, + async up(db, client) { + await db.command({ + createIndexes: 'users', + indexes: indexes, + }); + }, - async down(db, client) { - await db.command({ - dropIndexes: 'users', - index: ['googleID'], - }); - } + async down(db, client) { + await db.command({ + dropIndexes: 'users', + index: ['googleID'], + }); + }, }; diff --git a/data-serving/scripts/setup-db/migrations/20220713074716-additional-user-indexes.js b/data-serving/scripts/setup-db/migrations/20220713074716-additional-user-indexes.js new file mode 100644 index 000000000..f1b0cbd05 --- /dev/null +++ b/data-serving/scripts/setup-db/migrations/20220713074716-additional-user-indexes.js @@ -0,0 +1,28 @@ +const indexes = [ + { + name: 'email', + key: { + email: 1, + }, + collation: { + locale: 'en_US', + strength: 2, + }, + }, +]; + +module.exports = { + async up(db, client) { + await db.command({ + createIndexes: 'users', + indexes: indexes, + }); + }, + + async down(db, client) { + await db.command({ + dropIndexes: 'users', + index: ['email'], + }); + }, +}; diff --git a/verification/curator-service/api/src/controllers/auth.ts b/verification/curator-service/api/src/controllers/auth.ts index b3a6e82ec..e9eb3c201 100644 --- a/verification/curator-service/api/src/controllers/auth.ts +++ b/verification/curator-service/api/src/controllers/auth.ts @@ -660,8 +660,12 @@ export class AuthController { }, async (req, email, password, done) => { try { - const user = await users().findOne({ email }); + const userPromise = await users().find({ email }) + .collation({ locale: 'en_US', strength: 2 }) + .toArray(); + const user = userPromise[0]; + if (user) { return done(null, false, { message: 'Email address already exists', @@ -708,9 +712,12 @@ export class AuthController { }, async (email, password, done) => { try { - const user = (await users().findOne({ - email, - })) as IUser; + const userPromise = await users().find({ email }) + .collation({ locale: 'en_US', strength: 2 }) + .toArray(); + + const user = userPromise[0] as IUser; + if (!user) { return done(null, false, { message: 'Wrong username or password',