'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 (
); } if (!isAuthenticated) { return ; } return (
{/* Мобильный overlay */} {isSidebarOpen && (
setIsSidebarOpen(false)} /> )} {/* Sidebar */}
CKE Admin
{/* Main content */}
{/* Top bar */}
A
Добро пожаловать, admin
{/* Page content */}
{children}
); } // Компонент формы входа function LoginForm({ onLogin }: { onLogin: (email: string, password: string) => Promise }) { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); setError(''); if (!email || !password) { setError('Заполните все поля'); return; } onLogin(email, password).then((success) => { if (!success) setError('Неверный логин или пароль'); }); }; return (

CKE Admin Panel

Войдите в систему управления

setEmail(e.target.value)} className="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-transparent" placeholder="Введите email или логин" />
setPassword(e.target.value)} className="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-transparent" placeholder="Введите пароль" />
{error && (
{error}
)}
); }