Removed unused Promise resolves

This commit is contained in:
2022-03-06 10:34:39 +01:00
parent c6791a7027
commit 90f3d86511

View File

@@ -18,8 +18,8 @@ class UserSecurity {
} else if (clearPassword.trim() === "") { } else if (clearPassword.trim() === "") {
throw new Error("The password is empty."); throw new Error("The password is empty.");
} else { } else {
return Promise.resolve() return this.userRepository
.then(() => this.userRepository.create(user)) .create(user)
.then(() => UserSecurity.hashPassword(clearPassword)) .then(() => UserSecurity.hashPassword(clearPassword))
.then(hash => this.userRepository.changePassword(user, hash)); .then(hash => this.userRepository.changePassword(user, hash));
} }
@@ -32,8 +32,8 @@ class UserSecurity {
* @returns {Promise} * @returns {Promise}
*/ */
login(user, clearPassword) { login(user, clearPassword) {
return Promise.resolve() return this.userRepository
.then(() => this.userRepository.retrieveHash(user)) .retrieveHash(user)
.then(hash => UserSecurity.compareHashes(hash, clearPassword)) .then(hash => UserSecurity.compareHashes(hash, clearPassword))
.catch(() => { .catch(() => {
throw new Error("Incorrect username or password."); throw new Error("Incorrect username or password.");
@@ -64,6 +64,8 @@ class UserSecurity {
return new Promise(resolve => { return new Promise(resolve => {
const saltRounds = 10; const saltRounds = 10;
bcrypt.hash(clearPassword, saltRounds, (error, hash) => { bcrypt.hash(clearPassword, saltRounds, (error, hash) => {
if (error) reject(error);
resolve(hash); resolve(hash);
}); });
}); });