import React, { useState } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import { useMutation } from '@tanstack/react-query'; import { GraduationCap } from 'lucide-react'; import toast from 'react-hot-toast'; import { authApi } from '../api/client'; import { useAuthStore } from '../store/auth'; import type { TokenResponse } from '../types'; export function Login() { const navigate = useNavigate(); const { setAuth } = useAuthStore(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const login = useMutation({ mutationFn: () => authApi.login({ email, password }), onSuccess: (response) => { const data: TokenResponse = response.data; setAuth(data.user, data.access_token); toast.success(`Добро пожаловать, ${data.user.name}!`); navigate('/cabinet'); }, onError: (error: any) => { const msg = error.response?.data?.detail || 'Ошибка входа'; toast.error(msg); }, }); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); login.mutate(); }; return (

Вход

Войдите в свой аккаунт

setEmail(e.target.value)} required placeholder="ivan@example.com" className="w-full border border-gray-200 rounded-xl px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-500" />
setPassword(e.target.value)} required minLength={8} placeholder="••••••••" className="w-full border border-gray-200 rounded-xl px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-500" />

Нет аккаунта?{' '} Зарегистрироваться

); }