🐛 fix: access cookie via header on logout
Some checks failed
Integration Tests / integration-tests (pull_request) Failing after 51s
Some checks failed
Integration Tests / integration-tests (pull_request) Failing after 51s
This commit is contained in:
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user