🐛 fix: access cookie via header on logout
Some checks failed
Integration Tests / integration-tests (pull_request) Failing after 51s

This commit is contained in:
2026-02-15 22:58:24 +07:00
parent 42aa7ed8d3
commit c74597c57d
5 changed files with 15 additions and 11 deletions

View File

@ -2,10 +2,12 @@ import { Context } from "elysia";
import { mainErrorHandler } from "../../../helpers/error/handler";
import { logoutService } from "../services/http/logout.service";
import { returnWriteResponse } from "../../../helpers/callback/httpResponse";
import { parse } from "cookie";
export const logoutController = async (ctx: Context) => {
try {
const jwtToken = ctx.cookie.auth_token?.value;
const jwtToken = parse(ctx.request.headers.get("auth_token") || "")
.auth_token as string;
const serviceResponse = await logoutService(jwtToken);
return returnWriteResponse(
ctx.set,

View File

@ -2,13 +2,12 @@ import { Context } from "elysia";
import { tokenValidationService } from "../services/http/tokenValidation.service";
import { returnReadResponse } from "../../../helpers/callback/httpResponse";
import { mainErrorHandler } from "../../../helpers/error/handler";
import { parse } from "cookie";
export const tokenValidationController = (
ctx: Context & { body: { token: string } },
) => {
export const tokenValidationController = (ctx: Context) => {
try {
const { token } = ctx.body;
const validationResult = tokenValidationService(token);
const { auth_token } = parse(ctx.request.headers.get("cookie") || "");
const validationResult = tokenValidationService(auth_token as string);
return returnReadResponse(
ctx.set,
200,

View File

@ -1,11 +1,12 @@
import { AppError } from "../../../../helpers/error/instances/app";
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
import { jwtDecode } from "../../../../helpers/http/jwt/decode";
export const tokenValidationService = (payload: string) => {
try {
if (!payload) return null;
const decoded = jwtDecode(payload);
return decoded;
} catch (error) {
throw new AppError(500, "Token validation failed", error);
ErrorForwarder(error);
}
};