fix(login): убрать console.log с credentials
Refs EventHub/EventHubFrontAdmin#10 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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<string, string> = {
|
||||
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 (
|
||||
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}>
|
||||
<Card title="Вход" style={{ width: 400 }}>
|
||||
<Form onFinish={onFinish} layout="vertical">
|
||||
<Form form={form} onFinish={onFinish} layout="vertical">
|
||||
<Form.Item name="email" label="Email" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
<Input autoComplete="username" />
|
||||
</Form.Item>
|
||||
<Form.Item name="password" label="Пароль" rules={[{ required: true }]}>
|
||||
<Input.Password />
|
||||
<Input.Password autoComplete="current-password" />
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Button type="primary" htmlType="submit" block>
|
||||
@@ -38,4 +54,4 @@ const LoginPage: React.FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default LoginPage;
|
||||
export default LoginPage;
|
||||
|
||||
Reference in New Issue
Block a user