fixing in user and authentication

This commit is contained in:
rafiarrafif
2025-05-11 01:41:05 +07:00
parent 954d40df3b
commit 307c5e2d68
15 changed files with 122 additions and 96 deletions

View File

@ -1,11 +1,19 @@
import bcrypt from "bcrypt";
import { findUserByEmailOrUsernameService } from "../../user/services/findUserByEmailOrUsername.service";
import { LoginWithPasswordRequest } from "../auth.types";
import { AppError } from "../../../helpers/error/instances/app";
export const loginWithPasswordService = async (
data: LoginWithPasswordRequest
request: LoginWithPasswordRequest
) => {
try {
const userData = await findUserByEmailOrUsernameService(data.identifier);
// search for user data using an identifier (username or email)
const userData = await findUserByEmailOrUsernameService(request.identifier);
// Validate the password in the request with the existing one
if (!(await bcrypt.compare(request.password, userData.password)))
throw new AppError(401, "Password incorrect");
return userData;
} catch (error) {
throw error;