import { useState } from 'react' import { useNavigate } from 'react-router-dom' import { useTranslation } from 'react-i18next' import { useAuth } from '../hooks/useAuth' import { GameButton } from './common/GameButton' import './Login.css' function Login() { const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [loading, setLoading] = useState(false) const { login } = useAuth() const navigate = useNavigate() const { t } = useTranslation() const validateEmail = (email: string) => { const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ return re.test(email) } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError('') // Validation if (!validateEmail(email)) { setError(t('auth.errors.invalidEmail')) return } if (password.length < 6) { setError(t('auth.errors.passwordLength')) return } setLoading(true) try { await login(email, password) // Navigate to character selection after successful login navigate('/characters') } catch (err: any) { setError(err.response?.data?.detail || t('auth.errors.loginFailed')) } finally { setLoading(false) } } return (

{t('auth.loginTitle')}

{t('auth.loginSubtitle')}

setEmail(e.target.value)} placeholder={t('auth.emailPlaceholder')} required disabled={loading} autoComplete="email" />
setPassword(e.target.value)} placeholder={t('auth.passwordPlaceholderLogin')} required disabled={loading} autoComplete="current-password" />
{error &&
{error}
} { }} // Form will handle it via submit > {loading ? t('auth.loggingIn') : t('auth.login')}
navigate('/register')} disabled={loading} > {t('auth.registerLink')}
) } export default Login