({
+ resolver: zodResolver(loginSchema),
+ defaultValues: { email: '', password: '' },
+ });
- const onFinish = async (values: { email: string; password: string }) => {
+ const onFinish = async (values: LoginFormValues) => {
try {
await login(values.email, values.password);
navigate('/dashboard');
} catch (error) {
- message.error(getLoginErrorMessage(error));
+ if (isAxiosError(error)) {
+ const apiError = error.response?.data?.error;
+ if (typeof apiError === 'string') {
+ message.error(t(`login.${apiError}`, { defaultValue: apiError }));
+ return;
+ }
+ }
+ message.error(t('login.error'));
}
};
return (
-
-
-
+
+
+ }
+ />
-
-
+
+ }
+ />
-
diff --git a/src/schemas/loginSchema.ts b/src/schemas/loginSchema.ts
new file mode 100644
index 0000000..47f24e7
--- /dev/null
+++ b/src/schemas/loginSchema.ts
@@ -0,0 +1,8 @@
+import { z } from 'zod';
+
+export const loginSchema = z.object({
+ email: z.string().min(1, 'Email обязателен').email('Некорректный email'),
+ password: z.string().min(1, 'Пароль обязателен'),
+});
+
+export type LoginFormValues = z.infer;