@@ -4,20 +4,14 @@ 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({ name: ACCESS_TOKEN, ...cookieOptions });
|
||||
cookieStore.delete({ name: REFRESH_TOKEN, ...cookieOptions });
|
||||
cookieStore.delete({ name: AUTH_USER_ID, ...cookieOptions });
|
||||
cookieStore.delete({ name: CLAIM_NAME, ...cookieOptions });
|
||||
cookieStore.delete(ACCESS_TOKEN);
|
||||
cookieStore.delete(REFRESH_TOKEN);
|
||||
cookieStore.delete(AUTH_USER_ID);
|
||||
cookieStore.delete(CLAIM_NAME);
|
||||
return NextResponse.json({ message: "Logged out" }, { status: 200 });
|
||||
}
|
||||
|
||||
@@ -9,7 +9,10 @@ export function createTokenManager(config: AuthConfig) {
|
||||
|
||||
if (config.cookieDomain) return config.cookieDomain;
|
||||
|
||||
return undefined;
|
||||
const { hostname } = window.location;
|
||||
if (hostname === "localhost" || hostname === "127.0.0.1") return undefined;
|
||||
|
||||
return hostname;
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -62,9 +65,7 @@ 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,7 +96,6 @@ export function Header({ viewOnly }: { viewOnly?: boolean }) {
|
||||
};
|
||||
|
||||
// 쿠키 삭제 헬퍼 함수
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const clearClientCookies = () => {
|
||||
const actualHost = window.location.hostname;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user