| 1 | import { AdminSidebar } from "@/components/admin/admin-sidebar"; |
| 2 | import { auth } from "@/server/auth"; |
| 3 | import { redirect } from "next/navigation"; |
| 4 | import { ReactNode } from "react"; |
| 5 | |
| 6 | interface AdminLayoutProps { |
| 7 | children: ReactNode; |
| 8 | } |
| 9 | |
| 10 | export default async function AdminLayout({ children }: AdminLayoutProps) { |
| 11 | const session = await auth(); |
| 12 | |
| 13 | if (!session?.user) { |
| 14 | redirect("/login"); |
| 15 | } |
| 16 | |
| 17 | if (session.user.role !== "admin") { |
| 18 | redirect("/dashboard"); |
| 19 | } |
| 20 | |
| 21 | return ( |
| 22 | <div className="flex flex-col min-h-screen pt-14"> |
| 23 | <div className="flex flex-1 w-full"> |
| 24 | <AdminSidebar /> |
| 25 | <main className="flex-1 ml-0 md:ml-64 overflow-auto"> |
| 26 | <div className="container py-6 md:py-8 px-4 md:px-6">{children}</div> |
| 27 | </main> |
| 28 | </div> |
| 29 | </div> |
| 30 | ); |
| 31 | } |