From 90f3d865114f93b4abb2bf335ad3d66a2fcf3a62 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Sun, 6 Mar 2022 10:34:39 +0100 Subject: [PATCH] Removed unused Promise resolves --- seasoned_api/src/user/userSecurity.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/seasoned_api/src/user/userSecurity.js b/seasoned_api/src/user/userSecurity.js index 4c5556a..e05f469 100644 --- a/seasoned_api/src/user/userSecurity.js +++ b/seasoned_api/src/user/userSecurity.js @@ -18,8 +18,8 @@ class UserSecurity { } else if (clearPassword.trim() === "") { throw new Error("The password is empty."); } else { - return Promise.resolve() - .then(() => this.userRepository.create(user)) + return this.userRepository + .create(user) .then(() => UserSecurity.hashPassword(clearPassword)) .then(hash => this.userRepository.changePassword(user, hash)); } @@ -32,8 +32,8 @@ class UserSecurity { * @returns {Promise} */ login(user, clearPassword) { - return Promise.resolve() - .then(() => this.userRepository.retrieveHash(user)) + return this.userRepository + .retrieveHash(user) .then(hash => UserSecurity.compareHashes(hash, clearPassword)) .catch(() => { throw new Error("Incorrect username or password."); @@ -64,6 +64,8 @@ class UserSecurity { return new Promise(resolve => { const saltRounds = 10; bcrypt.hash(clearPassword, saltRounds, (error, hash) => { + if (error) reject(error); + resolve(hash); }); });