'use client'; import { useState, useEffect, type ReactNode } from 'react'; import AdminLogin from './components/AdminLogin'; import AdminDashboard from './components/AdminDashboard'; import './admin.css'; /** * Auth gate and panel chrome for every /admin route. Lives in the admin layout * rather than in each page, so navigating between tabs keeps the session check * and the header mounted instead of re-running them per route. */ export default function AdminShell({ children }: { children: ReactNode }) { const [authenticated, setAuthenticated] = useState(null); const [enabled, setEnabled] = useState(true); useEffect(() => { async function checkAuth() { try { const res = await fetch('/api/admin/auth'); const data = await res.json(); setAuthenticated(data.authenticated); setEnabled(data.enabled); } catch { setAuthenticated(false); } } checkAuth(); }, []); if (authenticated === null) { return (
); } if (!enabled) { return (

Admin Panel

The admin panel is not enabled. Set ADMIN_PASSWORD in your environment variables to activate it.

); } if (!authenticated) { return setAuthenticated(true)} />; } return setAuthenticated(false)}>{children}; }