'use client' import { useState, useEffect } from 'react' import { useRouter } from 'next/navigation' export default function AdminDashboardPage() { const router = useRouter() const [authenticated, setAuthenticated] = useState(false) const [loading, setLoading] = useState(true) useEffect(() => { // Check authentication fetch('/api/admin/check') .then((res) => res.json()) .then((data) => { if (data.authenticated) { setAuthenticated(true) } else { router.push('/admin/login') } }) .catch(() => { router.push('/admin/login') }) .finally(() => { setLoading(false) }) }, [router]) const handleLogout = async () => { await fetch('/api/admin/logout', { method: 'POST' }) router.push('/admin/login') } if (loading) { return (
Loading...