39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { cookies } from "next/headers";
|
|
import { NextResponse } from "next/server";
|
|
import {
|
|
ACCESS_TOKEN,
|
|
AUTH_USER_ID,
|
|
CLAIM_NAME,
|
|
REFRESH_TOKEN,
|
|
} from "@/shared/config";
|
|
|
|
export async function POST() {
|
|
const cookieStore = await cookies();
|
|
|
|
// 백엔드에 로그아웃 알림 (토큰 블랙리스트 처리)
|
|
const refreshToken = cookieStore.get(REFRESH_TOKEN)?.value;
|
|
|
|
if (refreshToken) {
|
|
try {
|
|
// ⭐ Spring Boot 백엔드에 로그아웃 요청
|
|
await fetch(`${process.env.NEXT_PUBLIC_SERVER_API_URL}/api/auth/logout`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"Cookie": `${REFRESH_TOKEN}=${refreshToken}`,
|
|
},
|
|
// credentials: "include", // fetch에서는 직접 쿠키 전달
|
|
});
|
|
} catch (error) {
|
|
console.error("Backend logout failed:", error);
|
|
}
|
|
}
|
|
|
|
// Next.js 쿠키 삭제
|
|
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 });
|
|
} |