36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { cookies } from "next/headers";
|
|
import { NextRequest, NextResponse } from "next/server";
|
|
import {
|
|
ACCESS_TOKEN,
|
|
AUTH_USER_ID,
|
|
CLAIM_NAME,
|
|
REFRESH_TOKEN,
|
|
} from "@/shared/config";
|
|
|
|
export async function POST(request: NextRequest) {
|
|
const cookieStore = await cookies();
|
|
|
|
// 쿠버네티스 환경: x-forwarded-host 또는 host 헤더에서 실제 도메인 가져오기
|
|
const forwardedHost = request.headers.get("x-forwarded-host");
|
|
const host = request.headers.get("host");
|
|
const actualHost = forwardedHost || host || request.nextUrl.hostname;
|
|
|
|
// 운영 환경에서 domain 설정
|
|
const domain = actualHost.includes("hasuon.or.kr") ? ".hasuon.or.kr" : undefined;
|
|
|
|
const cookieOptions = {
|
|
httpOnly: true,
|
|
sameSite: "lax" as const,
|
|
path: "/",
|
|
maxAge: 0, // 즉시 만료
|
|
...(domain && { domain }),
|
|
};
|
|
|
|
cookieStore.set(ACCESS_TOKEN, "", cookieOptions);
|
|
cookieStore.set(REFRESH_TOKEN, "", cookieOptions);
|
|
cookieStore.set(AUTH_USER_ID, "", cookieOptions);
|
|
cookieStore.set(CLAIM_NAME, "", cookieOptions);
|
|
|
|
return NextResponse.json({ message: "Logged out" }, { status: 200 });
|
|
}
|