'use client'; import { useState, useEffect } from 'react'; import Link from 'next/link'; export default function Home() { const [loggedIn, setLoggedIn] = useState(false); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); useEffect(() => { if (localStorage.getItem('auth')) { window.location.href = '/domains'; } }, []); const handleLogin = async () => { setError(''); setLoading(true); try { const response = await fetch('/api/auth', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ password }), }); if (response.ok) { const auth = btoa(`admin:${password}`); localStorage.setItem('auth', auth); window.location.href = '/domains'; } else { setError('Falsches Passwort'); } } catch (err) { setError('Verbindungsfehler. Bitte erneut versuchen.'); } finally { setLoading(false); } }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !loading) { handleLogin(); } }; if (!loggedIn) { return (