'use client'; import React, { useState, useEffect } from 'react'; import Link from 'next/link'; import { usePathname, useRouter } from 'next/navigation'; import { Building, FileText, Settings, LogOut, Menu, X } from 'lucide-react'; import S3Status from './components/S3Status'; interface AdminLayoutProps { children: React.ReactNode; } export default function AdminLayout({ children }: AdminLayoutProps) { const [isAuthenticated, setIsAuthenticated] = useState(false); const [isLoading, setIsLoading] = useState(true); const [isSidebarOpen, setIsSidebarOpen] = useState(false); const pathname = usePathname(); const router = useRouter(); useEffect(() => { const checkAuth = async () => { try { const res = await fetch('/api/admin/me', { cache: 'no-store' }); setIsAuthenticated(res.ok); } catch (e) { setIsAuthenticated(false); } finally { setIsLoading(false); } }; checkAuth(); }, []); const handleLogin = async (email: string, password: string) => { try { const res = await fetch('/api/admin/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ identifier: email, password }) }); if (res.ok) { setIsAuthenticated(true); return true; } return false; } catch (e) { return false; } }; const handleLogout = async () => { try { await fetch('/api/admin/logout', { method: 'POST' }); } finally { setIsAuthenticated(false); router.push('/admin'); } }; const navigation = [ { name: 'Новости', href: '/admin/news', icon: FileText }, { name: 'Настройки', href: '/admin/settings', icon: Settings }, ]; if (isLoading) { return (
Войдите в систему управления