layout.tsx44 lines, 1015 B
| 1 | "use client"; |
| 2 | |
| 3 | import { useAuth } from "@/lib/hooks/auth"; |
| 4 | import SidebarNav from "./dashboard/components/sidebar-nav"; |
| 5 | import { useRouter } from "next/navigation"; |
| 6 | import { useEffect } from "react"; |
| 7 | |
| 8 | export default function DashboardLayout({ |
| 9 | children, |
| 10 | }: { |
| 11 | children: React.ReactNode; |
| 12 | }) { |
| 13 | const { user, loading } = useAuth(); |
| 14 | const router = useRouter(); |
| 15 | |
| 16 | useEffect(() => { |
| 17 | if (!loading && !user) { |
| 18 | router.push("/auth/login?redirect=/dashboard"); |
| 19 | } |
| 20 | }, [user, loading, router]); |
| 21 | |
| 22 | if (loading) { |
| 23 | return <div>Loading...</div>; |
| 24 | } |
| 25 | |
| 26 | if (!user) { |
| 27 | return null; |
| 28 | } |
| 29 | |
| 30 | return ( |
| 31 | <div className="flex h-screen"> |
| 32 | <SidebarNav /> |
| 33 | <div className="flex flex-col flex-1 overflow-hidden"> |
| 34 | <main className="flex-1 relative overflow-y-auto focus:outline-none"> |
| 35 | <div className="py-6"> |
| 36 | <div className="max-w-7xl mx-auto px-4 sm:px-6 md:px-8"> |
| 37 | {children} |
| 38 | </div> |
| 39 | </div> |
| 40 | </main> |
| 41 | </div> |
| 42 | </div> |
| 43 | ); |
| 44 | } |