88 lines
3.1 KiB
JavaScript
88 lines
3.1 KiB
JavaScript
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 (
|
|
<div className="min-h-screen bg-gray-50">
|
|
{/* Admin Header */}
|
|
<header className="bg-white shadow-sm border-b">
|
|
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
|
<div className="flex justify-between items-center h-16">
|
|
<div className="flex items-center space-x-8">
|
|
<h1 className="text-xl font-semibold text-gray-900">
|
|
Admin Panel
|
|
</h1>
|
|
<nav className="flex space-x-4">
|
|
<button
|
|
onClick={() => router.push('/admin')}
|
|
className={`px-3 py-2 rounded-md text-sm font-medium ${
|
|
router.pathname === '/admin'
|
|
? 'bg-gray-100 text-gray-900'
|
|
: 'text-gray-600 hover:text-gray-900 hover:bg-gray-50'
|
|
}`}
|
|
>
|
|
DevLog
|
|
</button>
|
|
<button
|
|
onClick={() => router.push('/admin/blog')}
|
|
className={`px-3 py-2 rounded-md text-sm font-medium ${
|
|
router.pathname === '/admin/blog'
|
|
? 'bg-gray-100 text-gray-900'
|
|
: 'text-gray-600 hover:text-gray-900 hover:bg-gray-50'
|
|
}`}
|
|
>
|
|
Blog
|
|
</button>
|
|
</nav>
|
|
</div>
|
|
<button
|
|
onClick={handleLogout}
|
|
disabled={isLoggingOut}
|
|
className="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-red-600 hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 disabled:opacity-50 disabled:cursor-not-allowed"
|
|
>
|
|
{isLoggingOut ? 'Wird abgemeldet...' : 'Abmelden'}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
{/* Main Content */}
|
|
<main className="max-w-7xl mx-auto py-6 sm:px-6 lg:px-8">
|
|
<div className="px-4 py-6 sm:px-0">
|
|
{children}
|
|
</div>
|
|
</main>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default AdminLayout; |