|
1 | | -import { cookies } from "next/headers"; |
2 | 1 | import RouteBreadcrumb from "@/components/common/RouteBreadcrumb"; |
3 | 2 | import AdminSidebar from "@/components/layout/AdminSidebar"; |
4 | 3 |
|
5 | | -import { jwtDecode } from "jwt-decode"; |
6 | | -import { redirect } from "next/navigation"; |
7 | | -import { AuthJwtPayload } from "@/types"; |
8 | 4 | import { Separator } from "@/components/ui/Separator"; |
9 | 5 | import { SidebarInset, SidebarProvider, SidebarTrigger } from "@/components/ui/Sidebar"; |
| 6 | +import ProtectedRoute from "@/components/layout/ProtectedRoute"; |
10 | 7 |
|
11 | 8 | export default async function AdminLayout({ children }: { children: React.ReactNode }) { |
12 | | - const cookieStore = await cookies(); |
13 | | - const token = cookieStore.get("token"); |
14 | | - |
15 | | - if (!token) return redirect("/"); |
16 | | - |
17 | | - const payload = jwtDecode<AuthJwtPayload>(token.value); |
18 | | - if (payload.role !== "admin") return redirect("/"); |
19 | | - |
20 | 9 | return ( |
21 | 10 | <SidebarProvider> |
22 | | - <AdminSidebar /> |
23 | | - <SidebarInset> |
24 | | - <header className="flex h-16 shrink-0 items-center gap-2 transition-[width,height] ease-linear group-has-data-[collapsible=icon]/sidebar-wrapper:h-12"> |
25 | | - <div className="flex items-center gap-2 px-4"> |
26 | | - <SidebarTrigger className="-ml-1" /> |
27 | | - <Separator orientation="vertical" className="mr-2 data-[orientation=vertical]:h-4" /> |
28 | | - <RouteBreadcrumb /> |
29 | | - </div> |
30 | | - </header> |
31 | | - <main className="p-4">{children}</main> |
32 | | - </SidebarInset> |
| 11 | + <ProtectedRoute requiredRole="admin"> |
| 12 | + <AdminSidebar /> |
| 13 | + <SidebarInset> |
| 14 | + <header className="flex h-16 shrink-0 items-center gap-2 transition-[width,height] ease-linear group-has-data-[collapsible=icon]/sidebar-wrapper:h-12"> |
| 15 | + <div className="flex items-center gap-2 px-4"> |
| 16 | + <SidebarTrigger className="-ml-1" /> |
| 17 | + <Separator orientation="vertical" className="mr-2 data-[orientation=vertical]:h-4" /> |
| 18 | + <RouteBreadcrumb /> |
| 19 | + </div> |
| 20 | + </header> |
| 21 | + <main className="p-4">{children}</main> |
| 22 | + </SidebarInset> |
| 23 | + </ProtectedRoute> |
33 | 24 | </SidebarProvider> |
34 | 25 | ); |
35 | 26 | } |
0 commit comments