diff --git a/plugins/talk-plugin-local-auth/server/errors.js b/plugins/talk-plugin-local-auth/server/errors.js index 808ceb3a6..0f0653c19 100644 --- a/plugins/talk-plugin-local-auth/server/errors.js +++ b/plugins/talk-plugin-local-auth/server/errors.js @@ -22,4 +22,14 @@ class ErrLocalProfile extends TalkError { } } -module.exports = { ErrLocalProfile, ErrNoLocalProfile }; +// ErrIncorrectPassword is returned when the password passed was incorrect. +class ErrIncorrectPassword extends TalkError { + constructor() { + super('Password was incorrect', { + translation_key: 'INCORRECT_PASSWORD', + status: 400, + }); + } +} + +module.exports = { ErrLocalProfile, ErrNoLocalProfile, ErrIncorrectPassword }; diff --git a/plugins/talk-plugin-local-auth/server/mutators.js b/plugins/talk-plugin-local-auth/server/mutators.js index fb866b92c..cb34bed7a 100644 --- a/plugins/talk-plugin-local-auth/server/mutators.js +++ b/plugins/talk-plugin-local-auth/server/mutators.js @@ -1,5 +1,9 @@ const { ErrNotAuthorized, ErrNotFound, ErrEmailTaken } = require('errors'); -const { ErrNoLocalProfile, ErrLocalProfile } = require('./errors'); +const { + ErrNoLocalProfile, + ErrLocalProfile, + ErrIncorrectPassword, +} = require('./errors'); const { get } = require('lodash'); const bcrypt = require('bcryptjs'); @@ -25,7 +29,7 @@ async function updateUserEmailAddress(ctx, email, confirmPassword) { // Ensure that the password provided matches what we have on file. if (!await user.verifyPassword(confirmPassword)) { - throw new ErrNotAuthorized(); + throw new ErrIncorrectPassword(); } // Cleanup the email address. diff --git a/plugins/talk-plugin-local-auth/server/translations.yml b/plugins/talk-plugin-local-auth/server/translations.yml index 7df3d7b88..d81de6c6d 100644 --- a/plugins/talk-plugin-local-auth/server/translations.yml +++ b/plugins/talk-plugin-local-auth/server/translations.yml @@ -6,3 +6,4 @@ en: error: NO_LOCAL_PROFILE: No existing email address is associated with this account. LOCAL_PROFILE: An email address is already associated with this account. + INCORRECT_PASSWORD: Provided password was incorrect.