diff --git a/plugins/talk-plugin-local-auth/server/mutators.js b/plugins/talk-plugin-local-auth/server/mutators.js index 389574d2d..147d06cd2 100644 --- a/plugins/talk-plugin-local-auth/server/mutators.js +++ b/plugins/talk-plugin-local-auth/server/mutators.js @@ -35,16 +35,24 @@ async function updateUserEmailAddress(ctx, email, confirmPassword) { email = email.toLowerCase().trim(); // Update the Users email address. - await User.update( - { - id: user.id, - profiles: { $elemMatch: { provider: 'local' } }, - }, - { - $set: { 'profiles.$.id': email }, - $unset: { 'profiles.$.metadata.confirmed_at': 1 }, + try { + await User.update( + { + id: user.id, + profiles: { $elemMatch: { provider: 'local' } }, + }, + { + $set: { 'profiles.$.id': email }, + $unset: { 'profiles.$.metadata.confirmed_at': 1 }, + } + ); + } catch (err) { + if (err.code === 11000) { + throw new ErrEmailTaken(); } - ); + + throw err; + } // Get some context for the email to be sent. const { organizationContactEmail } = await Settings.load([