@@ -0,0 +1,35 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import { useRouter, usePathname } from 'next/navigation';
|
||||
import { useAdmin } from '@/lib/AdminContext';
|
||||
import AdminSidebar from './AdminSidebar';
|
||||
|
||||
export default function AdminLayout({ children }: { children: React.ReactNode }) {
|
||||
const { isAuthenticated } = useAdmin();
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated && pathname !== '/admin') {
|
||||
router.push('/admin');
|
||||
}
|
||||
}, [isAuthenticated, router, pathname]);
|
||||
|
||||
if (!isAuthenticated && pathname !== '/admin') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (pathname === '/admin') {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-primary-900 via-primary-800 to-primary-900 flex">
|
||||
<AdminSidebar />
|
||||
<main className="flex-1 overflow-auto">
|
||||
{children}
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user