import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { Eye, EyeOff } from 'lucide-react'; import { motion } from 'framer-motion'; import { authService } from '../../services/authService'; import { useAuthStore } from '../../store/authStore'; export default function LoginForm() { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const [showPassword, setShowPassword] = useState(false); const navigate = useNavigate(); const setUser = useAuthStore((state) => state.setUser); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setIsLoading(true); try { const data = await authService.login({ username, password }); const user = await authService.getCurrentUser(); setUser(user); navigate('/chat'); } catch (err: any) { setError(err.response?.data?.detail || 'Ошибка входа'); } finally { setIsLoading(false); } }; return (
); }