import { useRouter } from 'next/router'; import { useState } from 'react'; const AdminLayout = ({ children }) => { const router = useRouter(); const [isLoggingOut, setIsLoggingOut] = useState(false); const handleLogout = async () => { setIsLoggingOut(true); try { // API-Route für Logout aufrufen await fetch('/api/logout', { method: 'POST', headers: { 'Content-Type': 'application/json', }, }); // Cookie clientseitig löschen (als Backup) document.cookie = 'isAuthenticated=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; // Zur Login-Seite weiterleiten router.push('/admin/login'); } catch (error) { console.error('Logout-Fehler:', error); // Fallback: Cookie trotzdem löschen und weiterleiten document.cookie = 'isAuthenticated=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; router.push('/admin/login'); } finally { setIsLoggingOut(false); } }; return (