From c6d2aa21de9e973546b9c04590ff17212af1167a Mon Sep 17 00:00:00 2001 From: uiuuoq Date: Fri, 1 May 2026 12:52:34 +0900 Subject: [PATCH] =?UTF-8?q?DP-421:=20=EB=A7=88=EC=9D=B4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EA=B0=80=EB=93=9C=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/(main)/my-page/layout.tsx | 33 +++++++++++++++++++++++++++++++++ app/(main)/my-page/page.tsx | 18 ++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 app/(main)/my-page/layout.tsx diff --git a/app/(main)/my-page/layout.tsx b/app/(main)/my-page/layout.tsx new file mode 100644 index 0000000..13d204b --- /dev/null +++ b/app/(main)/my-page/layout.tsx @@ -0,0 +1,33 @@ +"use client"; + +import { useEffect } from "react"; +import { useRouter, usePathname } from "next/navigation"; +import { useAuthStore } from "@/store/auth.store"; +import { useHydrated } from "@/lib/hooks/useHydrated"; + +export default function MyPageLayout({ + children, +}: { + children: React.ReactNode; +}) { + const isAuthenticated = useAuthStore((s) => s.isAuthenticated); + const isInitialized = useAuthStore((s) => s.isInitialized); + const mounted = useHydrated(); + const router = useRouter(); + const pathname = usePathname(); + + const isSubPage = pathname !== "/my-page"; + + useEffect(() => { + if (mounted && isInitialized && !isAuthenticated && isSubPage) { + router.replace("/my-page"); + } + }, [mounted, isInitialized, isAuthenticated, isSubPage, router]); + + if (!mounted || !isInitialized) return null; + + // 하위 페이지는 미인증 시 리다이렉트 대기 중 아무것도 표시 안 함 + if (!isAuthenticated && isSubPage) return null; + + return <>{children}; +} diff --git a/app/(main)/my-page/page.tsx b/app/(main)/my-page/page.tsx index 093738e..d5853ab 100644 --- a/app/(main)/my-page/page.tsx +++ b/app/(main)/my-page/page.tsx @@ -1,5 +1,23 @@ +"use client"; + +import { useAuthStore } from "@/store/auth.store"; +import { useHydrated } from "@/lib/hooks/useHydrated"; +import { LoginRequiredEmptyState } from "@/components/features/auth/LoginRequiredEmptyState"; import MyPage from "@/components/features/my-page/MyPage"; export default function Page() { + const isAuthenticated = useAuthStore((s) => s.isAuthenticated); + const isInitialized = useAuthStore((s) => s.isInitialized); + const mounted = useHydrated(); + + if (!mounted || !isInitialized) return null; + if (!isAuthenticated) + return ( + + ); + return ; }