From f3461e8fbe76b1a7eb9d2b94f5445bff48e74fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A7=80=EC=B2=A0?= Date: Thu, 2 Oct 2025 14:40:49 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BF=A0=ED=82=A4=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/cm/.gitignore | 2 ++ .../cm/src/entities/auth/lib/token-manager.ts | 25 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/apps/cm/.gitignore b/apps/cm/.gitignore index b63718b61..c3326d730 100644 --- a/apps/cm/.gitignore +++ b/apps/cm/.gitignore @@ -10,6 +10,8 @@ !.yarn/releases !.yarn/versions +pnpm_lock.yaml + # testing /coverage diff --git a/apps/cm/src/entities/auth/lib/token-manager.ts b/apps/cm/src/entities/auth/lib/token-manager.ts index 0e761486a..21ed00218 100644 --- a/apps/cm/src/entities/auth/lib/token-manager.ts +++ b/apps/cm/src/entities/auth/lib/token-manager.ts @@ -19,14 +19,37 @@ export class TokenManager { } public setToken(key: string, value: string): void { + // 환경에 따른 도메인 설정 + const domain = this.getCookieDomain(); + setCookie(key, value, { secure: window.location.protocol === "https:", sameSite: "lax", + domain: domain, + path: "/", // 모든 경로에서 접근 가능 }); } + private getCookieDomain(): string | undefined { + const hostname = window.location.hostname; + + // 개발 환경에서는 localhost 도메인 사용 + if (hostname === "localhost" || hostname === "127.0.0.1") { + return undefined; // localhost에서는 도메인 설정하지 않음 + } + + // 운영 환경에서는 서브도메인을 포함한 최상위 도메인 사용 + if (hostname.includes("hasuon.or.kr")) { + return ".hasuon.or.kr"; + } + + // 기타 환경에서는 현재 호스트명 사용 + return hostname; + } + public removeToken(key: string): void { - removeCookie(key); + const domain = this.getCookieDomain(); + removeCookie(key, { domain, path: "/" }); } public setupRefreshTimer(