feat: admin provider UI (types, hooks, guard, settings panel, conditional admin nav)

This commit is contained in:
2026-03-16 03:38:37 +01:00
parent 87f94fcc51
commit 89036ba62d
8 changed files with 367 additions and 26 deletions

View File

@@ -0,0 +1,27 @@
"use client";
import { useEffect, type ReactNode } from "react";
import { useRouter } from "next/navigation";
import { useCurrentUser } from "@/hooks/use-auth";
import { useAuthContext } from "@/context/auth-context";
export default function AdminLayout({ children }: { children: ReactNode }) {
const { token, isLoaded } = useAuthContext();
const router = useRouter();
const { data: user, isLoading } = useCurrentUser();
useEffect(() => {
if (!isLoaded) return;
if (!token) {
router.replace("/login");
return;
}
if (!isLoading && user && !user.is_admin) {
router.replace("/dashboard");
}
}, [isLoaded, token, user, isLoading, router]);
if (!isLoaded || isLoading || !user?.is_admin) return null;
return <>{children}</>;
}