From c91f6fdcf5e4ff76000a1f7b3411eaacbd6d75c9 Mon Sep 17 00:00:00 2001 From: Jiii-Eun Date: Wed, 17 Sep 2025 02:50:40 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Fix:=20=EB=82=B4=20=EB=8C=80=EC=8B=9C?= =?UTF-8?q?=EB=B3=B4=EB=93=9C=20=EC=95=84=EB=8B=90=EA=B2=BD=EC=9A=B0=20edi?= =?UTF-8?q?t=EC=A0=9C=ED=95=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/[id]/edit/layout.tsx | 27 +++++++++++++++++++ .../(protected)/dashboard/[id]/edit/page.tsx | 3 +++ src/lib/apiRequest.ts | 14 ++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/app/(protected)/dashboard/[id]/edit/layout.tsx diff --git a/src/app/(protected)/dashboard/[id]/edit/layout.tsx b/src/app/(protected)/dashboard/[id]/edit/layout.tsx new file mode 100644 index 0000000..7dcbd7d --- /dev/null +++ b/src/app/(protected)/dashboard/[id]/edit/layout.tsx @@ -0,0 +1,27 @@ +import { cookies } from "next/headers"; +import { redirect } from "next/navigation"; +import { apiRequest } from "@/lib/apiRequest"; +import { Dashboard } from "@/features/dashboard/types"; + +export default async function Layout({ + children, + params, +}: { + children: React.ReactNode; + params: { id: string }; +}) { + const cookieStore = await cookies(); + const cookie = cookieStore.get("accessToken")?.value; + const cookieHeader = cookie ? `accessToken=${cookie}` : ""; + + const dashboard = await apiRequest(`/dashboards/${params.id}`, { + method: "GET", + cookieHeader, + }); + + if (!dashboard.createdByMe) { + redirect(`/dashboard/${params.id}`); + } + + return <>{children}; +} diff --git a/src/app/(protected)/dashboard/[id]/edit/page.tsx b/src/app/(protected)/dashboard/[id]/edit/page.tsx index 6fe326f..58ec974 100644 --- a/src/app/(protected)/dashboard/[id]/edit/page.tsx +++ b/src/app/(protected)/dashboard/[id]/edit/page.tsx @@ -116,6 +116,9 @@ export default function DashboardIdEdit() { setDisplayName(dashboardName); alert("대시보드가 성공적으로 수정되었습니다."); + + queryClient.invalidateQueries({ queryKey: ["dashboards"] }); + queryClient.invalidateQueries({ queryKey: ["dashboard", dashboardId] }); } catch (e) { console.error("대시보드 수정 실패", e); alert("대시보드 수정에 실패했습니다."); diff --git a/src/lib/apiRequest.ts b/src/lib/apiRequest.ts index c3b612b..ad239a7 100644 --- a/src/lib/apiRequest.ts +++ b/src/lib/apiRequest.ts @@ -1,15 +1,18 @@ -const BASE_URL = "/api/proxy"; +const isServer = typeof window === "undefined"; + +const BASE_URL = isServer ? `${process.env.NEXT_PUBLIC_FRONT_URL}/api/proxy` : "/api/proxy"; interface FetchOptions extends Omit { isFormData?: boolean; data?: unknown; + cookieHeader?: string; } export async function apiRequest( endpoint: string, options: FetchOptions = {}, ): Promise { - const { isFormData, headers, data, ...rest } = options; + const { isFormData, headers, data, cookieHeader, ...rest } = options; const fetchOptions: RequestInit = { ...rest, @@ -19,6 +22,13 @@ export async function apiRequest( }, }; + if (cookieHeader) { + fetchOptions.headers = { + ...fetchOptions.headers, + Cookie: cookieHeader, + }; + } + if (!isFormData && data !== undefined) { fetchOptions.headers = { ...fetchOptions.headers, From 94e4ac9eef4f4ddcecc4a133cc162dab7324dab7 Mon Sep 17 00:00:00 2001 From: Jiii-Eun Date: Wed, 17 Sep 2025 13:25:34 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Fix:=20edit=EB=A0=88=EC=9D=B4=EC=95=84?= =?UTF-8?q?=EC=9B=83=20=ED=83=80=EC=9E=85=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(protected)/dashboard/[id]/edit/layout.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/(protected)/dashboard/[id]/edit/layout.tsx b/src/app/(protected)/dashboard/[id]/edit/layout.tsx index 7dcbd7d..08c145a 100644 --- a/src/app/(protected)/dashboard/[id]/edit/layout.tsx +++ b/src/app/(protected)/dashboard/[id]/edit/layout.tsx @@ -8,19 +8,21 @@ export default async function Layout({ params, }: { children: React.ReactNode; - params: { id: string }; + params: any; }) { const cookieStore = await cookies(); const cookie = cookieStore.get("accessToken")?.value; const cookieHeader = cookie ? `accessToken=${cookie}` : ""; - const dashboard = await apiRequest(`/dashboards/${params.id}`, { + const { id } = params as { id: string }; + + const dashboard = await apiRequest(`/dashboards/${id}`, { method: "GET", cookieHeader, }); if (!dashboard.createdByMe) { - redirect(`/dashboard/${params.id}`); + redirect(`/dashboard/${id}`); } return <>{children};