From 2d1e47b6663089e2c539781a1fa4a4727e0be4d9 Mon Sep 17 00:00:00 2001 From: dogukanoksuz Date: Wed, 13 Mar 2024 16:42:08 +0300 Subject: [PATCH] fix: Cookie logout issues --- src/services/api.service.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/services/api.service.ts b/src/services/api.service.ts index bdd893b..4676746 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -1,5 +1,7 @@ import axios, { AxiosInstance } from "axios" +import { useLogout } from "@/hooks/auth/useLogout" + export class ApiService { protected readonly instance: AxiosInstance public constructor(url: string) { @@ -20,8 +22,15 @@ export class ApiService { }, (error) => { if (error.response && error.response.status === 401) { - window.location.href = - "/auth/login?redirect=" + window.location.pathname + if (window.location.pathname == "/auth/login") { + return Promise.reject(error) + } + + const { logout } = useLogout() + logout().finally(() => { + window.location.href = + "/auth/login?redirect=" + window.location.pathname + }) } if (error.response && error.response.status === 504) { window.location.href = "/504"