Skip to content

Commit

Permalink
fix: Cookie logout issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Mar 13, 2024
1 parent 3514ce8 commit 2d1e47b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/services/api.service.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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"
Expand Down

0 comments on commit 2d1e47b

Please sign in to comment.