[cs] feat: 로그아웃 시 쿠키 제거 방식 변경

This commit is contained in:
2026-04-09 15:06:25 +09:00
parent 7bf86e8619
commit 6422b3013a
3 changed files with 20 additions and 14 deletions
+10 -4
View File
@@ -4,14 +4,20 @@ import {
ACCESS_TOKEN,
AUTH_USER_ID,
CLAIM_NAME,
COOKIE_DOMAIN,
REFRESH_TOKEN,
} from "@/shared/config";
const cookieOptions = {
path: "/",
domain: COOKIE_DOMAIN,
};
export async function POST() {
const cookieStore = await cookies();
cookieStore.delete(ACCESS_TOKEN);
cookieStore.delete(REFRESH_TOKEN);
cookieStore.delete(AUTH_USER_ID);
cookieStore.delete(CLAIM_NAME);
cookieStore.delete({ name: ACCESS_TOKEN, ...cookieOptions });
cookieStore.delete({ name: REFRESH_TOKEN, ...cookieOptions });
cookieStore.delete({ name: AUTH_USER_ID, ...cookieOptions });
cookieStore.delete({ name: CLAIM_NAME, ...cookieOptions });
return NextResponse.json({ message: "Logged out" }, { status: 200 });
}
+4 -5
View File
@@ -9,10 +9,7 @@ export function createTokenManager(config: AuthConfig) {
if (config.cookieDomain) return config.cookieDomain;
const { hostname } = window.location;
if (hostname === "localhost" || hostname === "127.0.0.1") return undefined;
return hostname;
return undefined;
};
return {
@@ -65,7 +62,9 @@ export function createTokenManager(config: AuthConfig) {
},
getRefreshToken(): string | undefined {
return config.refreshToken ? this.getToken(config.refreshToken) : undefined;
return config.refreshToken
? this.getToken(config.refreshToken)
: undefined;
},
getUserId(): string | undefined {
@@ -82,13 +82,13 @@ export function Header({ viewOnly }: { viewOnly?: boolean }) {
// 에러가 나도 계속 진행
} finally {
// 2. 클라이언트 쿠키 삭제 (백업)
clearClientCookies();
// clearClientCookies();
// 3. 로컬/세션 스토리지 정리
if (typeof window !== "undefined") {
localStorage.clear();
sessionStorage.clear();
}
// if (typeof window !== "undefined") {
// localStorage.clear();
// sessionStorage.clear();
// }
// 4. 로그인 페이지로 리다이렉트
window.location.href = "/auth/login";
@@ -96,6 +96,7 @@ export function Header({ viewOnly }: { viewOnly?: boolean }) {
};
// 쿠키 삭제 헬퍼 함수
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const clearClientCookies = () => {
const actualHost = window.location.hostname;