From 3268cb819ad3872f5ef9d0a9893f561e485f975b Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Thu, 24 Apr 2025 06:09:58 +0000 Subject: [PATCH] Fix indentation and remove unused hash login method --- .../classes/account/methods/loginStrategy.js | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/packages/server/services/auth/classes/account/methods/loginStrategy.js b/packages/server/services/auth/classes/account/methods/loginStrategy.js index 022bc603..537a2a27 100644 --- a/packages/server/services/auth/classes/account/methods/loginStrategy.js +++ b/packages/server/services/auth/classes/account/methods/loginStrategy.js @@ -2,13 +2,13 @@ import bcrypt from "bcrypt" import { User } from "@db_models" export default async ({ username, password, hash }, user) => { - if (typeof user === "undefined") { - let isEmail = username.match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/) + if (typeof user === "undefined") { + let isEmail = username.match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/) - let query = isEmail ? { email: username } : { username: username } + let query = isEmail ? { email: username } : { username: username } - user = await User.findOne(query).select("+email").select("+password") - } + user = await User.findOne(query).select("+email").select("+password") + } if (!user) { throw new OperationError(401, "User not found") @@ -18,15 +18,9 @@ export default async ({ username, password, hash }, user) => { throw new OperationError(401, "User is disabled") } - if (typeof hash !== "undefined") { - if (user.password !== hash) { - throw new OperationError(401, "Invalid credentials") - } - } else { - if (!bcrypt.compareSync(password, user.password)) { - throw new OperationError(401, "Invalid credentials") - } - } + if (!bcrypt.compareSync(password, user.password)) { + throw new OperationError(401, "Invalid credentials") + } - return user -} \ No newline at end of file + return user +}