Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions app/(main)/my-page/layout.tsx
Original file line number Diff line number Diff line change
@@ -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}</>;
}
18 changes: 18 additions & 0 deletions app/(main)/my-page/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<LoginRequiredEmptyState
title="로그인이 필요합니다"
description="마이페이지는 로그인 후 이용할 수 있습니다."
/>
);

return <MyPage />;
}
Loading