fix(auth): align session lifecycle with Keycloak
This commit is contained in:
+1
-8
@@ -1,6 +1,5 @@
|
||||
import axios, { AxiosHeaders, type InternalAxiosRequestConfig } from "axios";
|
||||
import { config } from "@config/config";
|
||||
import { signOut } from "next-auth/react";
|
||||
import { useAuthStore } from "@/store/authStore";
|
||||
import {
|
||||
applyAuthContextHeaders,
|
||||
@@ -13,8 +12,6 @@ export const api = axios.create({
|
||||
baseURL: API_URL,
|
||||
});
|
||||
|
||||
let isSigningOut = false;
|
||||
|
||||
export const resolveRequestUrl = (request: {
|
||||
baseURL?: string;
|
||||
url?: string;
|
||||
@@ -63,11 +60,7 @@ api.interceptors.response.use(
|
||||
},
|
||||
async (error) => {
|
||||
if (error?.response?.status === 401 && typeof window !== "undefined") {
|
||||
useAuthStore.getState().setAccessToken(null);
|
||||
if (!isSigningOut) {
|
||||
isSigningOut = true;
|
||||
await signOut({ redirect: true, callbackUrl: "/login" });
|
||||
}
|
||||
useAuthStore.getState().markSessionExpired("unauthorized");
|
||||
}
|
||||
return Promise.reject(error);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user