"use client"; import { useEffect } from "react"; import { useRouter } from "next/navigation"; import { useFeatureAccess, type ModuleKey } from "@/lib/useFeatureAccess"; interface FeatureGateProps { module: ModuleKey; children: React.ReactNode; fallback?: React.ReactNode; } export function FeatureGate({ module, children, fallback }: FeatureGateProps) { const { modules, loading } = useFeatureAccess(); const router = useRouter(); const allowed = modules.includes(module); useEffect(() => { if (!loading && !allowed) { router.replace("/"); } }, [loading, allowed, router]); if (loading) { return (
); } if (!allowed) { if (fallback) return <>{fallback}; return (

Access Restricted

You don't have access to this module.

); } return <>{children}; }