From 424fa576fb1839f85a10ede0eb6ee3b7cadedec2 Mon Sep 17 00:00:00 2001 From: bicochan Date: Tue, 7 Jul 2026 18:04:08 +0900 Subject: [PATCH] =?UTF-8?q?[cs]=20feat:=20auth=20service=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(BaseLayout=20DI=20=ED=8C=A8=ED=84=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/cs/app/(main)/(with-base-layout)/layout.tsx | 4 ++-- apps/cs/src/entities/auth/api/auth-service.ts | 15 +++++++++++++++ apps/cs/src/entities/auth/model/auth-interface.ts | 11 +---------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/apps/cs/app/(main)/(with-base-layout)/layout.tsx b/apps/cs/app/(main)/(with-base-layout)/layout.tsx index acc583e2e..a83a524b0 100644 --- a/apps/cs/app/(main)/(with-base-layout)/layout.tsx +++ b/apps/cs/app/(main)/(with-base-layout)/layout.tsx @@ -6,7 +6,7 @@ import { BaseLayout } from "@common/components"; import type { MenuItem } from "@/entities/menu"; import { useMenuStore } from "@/shared/lib"; import { PageLayout } from "@/shared/ui/page-layout"; -import { tokenManager } from "@/entities/auth"; +import { authService } from "@/entities/auth"; export default function WithBaseLayout({ children, @@ -27,7 +27,7 @@ export default function WithBaseLayout({ return ( diff --git a/apps/cs/src/entities/auth/api/auth-service.ts b/apps/cs/src/entities/auth/api/auth-service.ts index 9837aac8e..6f450a097 100644 --- a/apps/cs/src/entities/auth/api/auth-service.ts +++ b/apps/cs/src/entities/auth/api/auth-service.ts @@ -1,5 +1,6 @@ import { ACCESS_TOKEN, + AUTH_LOGIN_REDIRECT_URL, AUTH_USER_ID, CLAIM_NAME, ENDPOINT, @@ -8,6 +9,7 @@ import { getRemainingMs } from "@common/auth"; import { clearAuthToken, + removeToken, setToken, setupRefreshTimer, } from "../lib/token-manager"; @@ -99,9 +101,22 @@ async function silentRefresh(): Promise { } async function logout(): Promise { + try { + await fetch("/api/auth/logout", { + method: "POST", + credentials: "include", + }); + } catch (error) { + console.error("Logout API failed:", error); + } + clearAuthToken(); + removeToken("site-id-key"); + removeToken("site-theme-key"); + if (typeof window !== "undefined") { window.dispatchEvent(new CustomEvent("auth:logout")); + window.location.href = AUTH_LOGIN_REDIRECT_URL; } } diff --git a/apps/cs/src/entities/auth/model/auth-interface.ts b/apps/cs/src/entities/auth/model/auth-interface.ts index c4b2d2691..97078052e 100644 --- a/apps/cs/src/entities/auth/model/auth-interface.ts +++ b/apps/cs/src/entities/auth/model/auth-interface.ts @@ -1,10 +1 @@ -export interface AuthPayload { - userId: string; - password: string; -} - -export interface AuthService { - login(payload: AuthPayload): Promise; - silentRefresh(): Promise; - logout(): Promise; -} +export type { AuthPayload, AuthService } from "@common/auth";