🐛 (user) fix user check password

This commit is contained in:
unknown
2025-07-01 00:55:25 +07:00
parent e7857e0384
commit 3ef7f1a249
7 changed files with 82 additions and 19 deletions

View File

@ -2,11 +2,26 @@ import { Context } from "elysia";
import { checkUserPasswordService } from "../services/checkUserPassword.service";
import { jwtDecode } from "../../../helpers/http/jwt/decode";
import { getCookie } from "../../../helpers/http/userHeader/cookies/getCookies";
import { mainErrorHandler } from "../../../helpers/error/handler";
import { returnWriteResponse } from "../../../helpers/callback/httpResponse";
export const checkUserPasswordController = async (
ctx: Context & { body: { password: string } }
) => {
const cookie = getCookie(ctx);
const jwtPayload = jwtDecode(cookie.auth_token!);
return checkUserPasswordService(jwtPayload, ctx.body.password);
try {
const cookie = getCookie(ctx);
const jwtPayload = jwtDecode(cookie.auth_token!);
const checkUserPassword = await checkUserPasswordService(
jwtPayload.user.username,
ctx.body.password
);
return returnWriteResponse(
ctx.set,
204,
"Password is valid",
checkUserPassword
);
} catch (error) {
return mainErrorHandler(ctx.set, error);
}
};