diff --git a/devfront/src/lib/apiClient.ts b/devfront/src/lib/apiClient.ts index b362ba79..d379910f 100644 --- a/devfront/src/lib/apiClient.ts +++ b/devfront/src/lib/apiClient.ts @@ -1,4 +1,5 @@ import axios from "axios"; +import { userManager } from "./auth"; const apiClient = axios.create({ baseURL: @@ -7,15 +8,15 @@ const apiClient = axios.create({ "/api/v1", }); -apiClient.interceptors.request.use((config) => { - // TODO: IdP 중립 Auth 레이어 연동 시 세션 토큰을 주입한다. - const sessionToken = window.localStorage.getItem("admin_session"); - if (sessionToken) { - config.headers.Authorization = `Bearer ${sessionToken}`; +apiClient.interceptors.request.use(async (config) => { + // OIDC Access Token 주입 + const user = await userManager.getUser(); + if (user?.access_token) { + config.headers.Authorization = `Bearer ${user.access_token}`; } // TODO: 테넌트 선택 값을 보관하고 헤더로 전달한다. - const tenantId = window.localStorage.getItem("admin_tenant"); + const tenantId = window.localStorage.getItem("dev_tenant_id"); // 키 이름을 좀 더 명확하게 변경 고려 if (tenantId) { config.headers["X-Tenant-ID"] = tenantId; } @@ -26,7 +27,11 @@ apiClient.interceptors.request.use((config) => { apiClient.interceptors.response.use( (response) => response, (error) => { - // TODO: 401/403 응답 시 로그인/재인증 플로우로 리다이렉션한다. + if (error.response?.status === 401) { + // 401 발생 시 로그인 페이지로 리다이렉트하거나 토큰 갱신 로직 필요 + // 여기서는 간단히 리다이렉트 처리 (userManager 사용) + userManager.signinRedirect(); + } return Promise.reject(error); }, ); diff --git a/devfront/vite.config.ts b/devfront/vite.config.ts index 4b6f15a4..460b97bb 100644 --- a/devfront/vite.config.ts +++ b/devfront/vite.config.ts @@ -13,4 +13,7 @@ export default defineConfig({ }, }, }, + esbuild: { + // drop: process.env.APP_ENV === "production" ? ["console", "debugger"] : [], + }, });