Fixed email in use error

This commit is contained in:
Wyatt Johnson
2018-05-07 17:51:46 -06:00
parent 926364ad72
commit 08a857e07c
@@ -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([