From 7a25cf40aa170ddeaf3a993ae460c8561fb13cf0 Mon Sep 17 00:00:00 2001 From: kyy Date: Wed, 11 Feb 2026 17:33:54 +0900 Subject: [PATCH] =?UTF-8?q?API=20=ED=81=B4=EB=9D=BC=EC=9D=B4=EC=96=B8?= =?UTF-8?q?=ED=8A=B8=20=EB=B0=8F=20=EA=B0=9C=EB=B0=9C=20=EC=84=9C=EB=B2=84?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- devfront/src/lib/apiClient.ts | 19 ++++++++++++------- devfront/vite.config.ts | 3 +++ 2 files changed, 15 insertions(+), 7 deletions(-) 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"] : [], + }, });