import React, { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useAuth } from './useAuth'; export default function Login() { const { login, loading, error, logout } = useAuth(); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [message, setMessage] = useState(null); const isDev = import.meta.env.MODE !== 'production'; const navigate = useNavigate(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setMessage(null); try { await login(username, password); setMessage('Login erfolgreich'); // Redirect to dashboard after successful login navigate('/'); } catch (err) { setMessage(err instanceof Error ? err.message : 'Login fehlgeschlagen'); } }; return (

Anmeldung

{message &&
{message}
} {error &&
{error}
}
setUsername(e.target.value)} disabled={loading} style={{ width: '100%', padding: 8 }} autoFocus />
setPassword(e.target.value)} disabled={loading} style={{ width: '100%', padding: 8 }} />
{isDev && ( )}
); }