diff --git a/src/app/dashboard/layout.tsx b/src/app/dashboard/layout.tsx new file mode 100644 index 0000000..27140af --- /dev/null +++ b/src/app/dashboard/layout.tsx @@ -0,0 +1,44 @@ +"use client"; + +import { useEffect } from "react"; +import { useRouter } from "next/navigation"; +import { useAuthStore } from "@/store/authStore"; +import Sidebar from "@/components/layout/Sidebar"; +import Header from "@/components/layout/Header"; + +export default function DashboardLayout({ + children, +}: { + children: React.ReactNode; +}) { + const router = useRouter(); + const { isAuthenticated, checkAuth } = useAuthStore(); + + useEffect(() => { + checkAuth(); + }, [checkAuth]); + + useEffect(() => { + if (!isAuthenticated) { + router.replace("/login"); + } + }, [isAuthenticated, router]); + + if (!isAuthenticated) { + return ( +
+
+
+ ); + } + + return ( +
+ +
+
+
{children}
+
+
+ ); +}