feat, fix: - 로그아웃 로직 추가(수정중)

- 로그인 에러 수정
This commit is contained in:
swcho
2025-11-06 09:32:01 +09:00
parent c1a7dd946c
commit 8e156485c3
9 changed files with 92 additions and 17 deletions
+13 -4
View File
@@ -9,9 +9,18 @@ import {
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);
const cookieOptions = {
httpOnly: true,
sameSite: "lax" as const,
path: "/",
maxAge: 0, // 즉시 만료
};
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 });
}
+12
View File
@@ -0,0 +1,12 @@
import { NextRequest, NextResponse } from "next/server";
export async function GET(request: NextRequest) {
const hostname = request.nextUrl.hostname;
const redirectUrl = process.env.NEXT_PUBLIC_CM_LOGIN_PAGE_URL || "https://queen.hasuon.or.kr";
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr") {
return NextResponse.redirect(new URL("/", request.url)); // 로컬 및 개발 환경
} else {
return NextResponse.redirect(new URL(redirectUrl)); // 공단 환경
}
}
+2 -1
View File
@@ -9,9 +9,10 @@ import { useRouter } from "next/navigation";
export default function Home() {
const router = useRouter();
const checkToken = getCookie(AUTH_USER_ID);
const hostname = window.location.hostname;
useEffect(() => {
const hostname = window.location.hostname;
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr") {
if (!checkToken) {
async function doLogin() {
+24 -6
View File
@@ -1,5 +1,5 @@
import { cookies } from "next/headers";
import { NextResponse } from "next/server";
import { NextRequest, NextResponse } from "next/server";
import {
ACCESS_TOKEN,
AUTH_USER_ID,
@@ -7,11 +7,29 @@ import {
REFRESH_TOKEN,
} from "@/shared/config";
export async function POST() {
export async function POST(request: NextRequest) {
const cookieStore = await cookies();
cookieStore.delete(ACCESS_TOKEN);
cookieStore.delete(REFRESH_TOKEN);
cookieStore.delete(AUTH_USER_ID);
cookieStore.delete(CLAIM_NAME);
// 쿠버네티스 환경: 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 });
}
+12
View File
@@ -0,0 +1,12 @@
import { NextRequest, NextResponse } from "next/server";
export async function GET(request: NextRequest) {
const hostname = request.nextUrl.hostname;
const redirectUrl = process.env.NEXT_PUBLIC_CM_LOGIN_PAGE_URL || "https://queen.hasuon.or.kr";
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr") {
return NextResponse.redirect(new URL("/", request.url)); // 로컬 및 개발 환경
} else {
return NextResponse.redirect(new URL(redirectUrl)); // 공단 환경
}
}
+2 -1
View File
@@ -24,9 +24,10 @@ import { useRouter } from "next/navigation";
export default function Home() {
const router = useRouter();
const checkToken = getCookie(AUTH_USER_ID);
const hostname = window.location.hostname;
useEffect(() => {
const hostname = window.location.hostname;
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr") {
if (!checkToken) {
async function doLogin() {
+13 -4
View File
@@ -9,9 +9,18 @@ import {
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);
const cookieOptions = {
httpOnly: true,
sameSite: "lax" as const,
path: "/",
maxAge: 0, // 즉시 만료
};
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 });
}
+12
View File
@@ -0,0 +1,12 @@
import { NextRequest, NextResponse } from "next/server";
export async function GET(request: NextRequest) {
const hostname = request.nextUrl.hostname;
const redirectUrl = process.env.NEXT_PUBLIC_CM_LOGIN_PAGE_URL || "https://queen.hasuon.or.kr";
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr") {
return NextResponse.redirect(new URL("/", request.url)); // 로컬 및 개발 환경
} else {
return NextResponse.redirect(new URL(redirectUrl)); // 공단 환경
}
}
+2 -1
View File
@@ -10,9 +10,10 @@ import { useRouter } from "next/navigation";
export default function Home() {
const router = useRouter();
const checkToken = getCookie(AUTH_USER_ID);
const hostname = window.location.hostname;
useEffect(() => {
const hostname = window.location.hostname;
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr") {
if (!checkToken) {
async function doLogin() {