"use client"; import { useAuth } from "@/lib/auth-context"; import { ManagerProvider } from "@/lib/manager-context"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useEffect } from "react"; import type { ManagerLayoutProps } from "./ManagerLayout.types"; /** * Manager layout template — wraps content with auth guard and ManagerProvider. * Redirects non-managers away; shows loading state while auth resolves. */ export default function ManagerLayout({ children }: ManagerLayoutProps) { const { user } = useAuth(); const router = useRouter(); useEffect(() => { if (user !== null && user.role !== "manager") { router.replace("/"); } }, [user, router]); if (user === null) { return (

Đang kiểm tra quyền truy cập...

Đăng nhập nếu chưa có tài khoản
); } if (user.role !== "manager") return null; return (
{children}
); }