fixing in user and authentication
This commit is contained in:
@ -3,7 +3,7 @@ import { loginWithPasswordService } from "../services/loginWithPassword.service"
|
||||
import { loginWithPasswordSchema } from "../auth.schema";
|
||||
import { returnErrorResponse } from "../../../helpers/callback/httpResponse";
|
||||
import { LoginWithPasswordRequest } from "../auth.types";
|
||||
import { AppError } from "../../../helpers/error/handler";
|
||||
import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||
|
||||
export const loginWithPassword = async (
|
||||
ctx: Context & { body: LoginWithPasswordRequest }
|
||||
@ -16,13 +16,6 @@ export const loginWithPassword = async (
|
||||
const result = await loginWithPasswordService(ctx.body);
|
||||
return result;
|
||||
} catch (error) {
|
||||
if (error instanceof AppError) {
|
||||
return returnErrorResponse(
|
||||
ctx.set,
|
||||
error.statusCode,
|
||||
error.message,
|
||||
error.details
|
||||
);
|
||||
}
|
||||
return mainErrorHandler(ctx.set, error);
|
||||
}
|
||||
};
|
||||
|
||||
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user