From 8330c0168e33880af1b82a1c50f04bce9ba5c7b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A7=80=EC=B2=A0?= Date: Fri, 17 Oct 2025 09:43:18 +0900 Subject: [PATCH] Cookie Domain --- .../cs/src/entities/auth/lib/token-manager.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/apps/cs/src/entities/auth/lib/token-manager.ts b/apps/cs/src/entities/auth/lib/token-manager.ts index 0e761486a..5163f19c9 100644 --- a/apps/cs/src/entities/auth/lib/token-manager.ts +++ b/apps/cs/src/entities/auth/lib/token-manager.ts @@ -19,12 +19,32 @@ export class TokenManager { } public setToken(key: string, value: string): void { + const domain = this.getCookieDomain(); + setCookie(key, value, { secure: window.location.protocol === "https:", sameSite: "lax", }); } + + 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); }