diff --git a/src/pages/auth/LoginPage.tsx b/src/pages/auth/LoginPage.tsx index fea9d0c..28d6a08 100644 --- a/src/pages/auth/LoginPage.tsx +++ b/src/pages/auth/LoginPage.tsx @@ -1,31 +1,47 @@ import React from 'react'; import { Form, Input, Button, Card, message } from 'antd'; import { useNavigate } from 'react-router-dom'; +import { isAxiosError } from 'axios'; import { useAuthStore } from '../../store/authStore'; +const LOGIN_ERROR_MESSAGES: Record = { + invalid_credentials: 'Неверный email или пароль', + insufficient_permissions: 'Недостаточно прав для входа', +}; + +const getLoginErrorMessage = (error: unknown): string => { + if (isAxiosError(error)) { + const apiError = error.response?.data?.error; + if (typeof apiError === 'string') { + return LOGIN_ERROR_MESSAGES[apiError] ?? apiError; + } + } + return 'Ошибка входа'; +}; + const LoginPage: React.FC = () => { const navigate = useNavigate(); const login = useAuthStore((s) => s.login); + const [form] = Form.useForm(); const onFinish = async (values: { email: string; password: string }) => { - console.log('Form submitted', values); try { await login(values.email, values.password); navigate('/dashboard'); } catch (error) { - message.error('Ошибка входа'); + message.error(getLoginErrorMessage(error)); } }; return (
-
+ - + - +