import { useState } from 'react' import { useNavigate } from 'react-router-dom' import { useTranslation } from 'react-i18next' import { useAuthStore } from '@/store/authStore' import { apiClientV2 } from '@/services/apiV2' import { Lock, User, LayoutDashboard, AlertCircle, Loader2 } from 'lucide-react' import LanguageSwitcher from '@/components/LanguageSwitcher' export default function LoginPage() { const { t } = useTranslation() const navigate = useNavigate() const setUser = useAuthStore((state) => state.setUser) const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [loading, setLoading] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError('') setLoading(true) try { const response = await apiClientV2.login({ username, password }) setUser({ id: response.user.id, username: response.user.email, email: response.user.email, displayName: response.user.display_name }) navigate('/upload') } catch (err: any) { const errorDetail = err.response?.data?.detail if (Array.isArray(errorDetail)) { setError(errorDetail.map((e: any) => e.msg || e.message || String(e)).join(', ')) } else if (typeof errorDetail === 'string') { setError(errorDetail) } else { setError(t('auth.loginError')) } } finally { setLoading(false) } } return (
{t('app.subtitle')}
{t('auth.loginPrompt')}
{t('auth.supportedFormats')}