diff --git a/src/api/usePhoneAuth.ts b/src/api/usePhoneAuth.ts index 9b94018..b398558 100644 --- a/src/api/usePhoneAuth.ts +++ b/src/api/usePhoneAuth.ts @@ -51,7 +51,7 @@ export const useSendCode = () => { return useMutation({ mutationKey: ["auth", "send-code"], mutationFn: async (data: SendCodeDto) => { - const response = await client.post("/auth/phone/send-code", data); + const response = await client.post("/auth/send-code", data); return response.data; }, }); @@ -66,7 +66,7 @@ export const useVerifyCode = () => { mutationKey: ["auth", "verify-code"], mutationFn: async (data: VerifyCodeDto) => { const response = await client.post( - "/auth/phone/verify-code", + "/auth/verify-code", data ); diff --git a/src/components/layout/AuthDialog.tsx b/src/components/layout/AuthDialog.tsx index 172d50e..a8b9fbe 100644 --- a/src/components/layout/AuthDialog.tsx +++ b/src/components/layout/AuthDialog.tsx @@ -81,15 +81,15 @@ export default function AuthDialog({ isOpen, onClose }: AuthDialogProps) { setError(null); try { - // await sendCodeMutation.mutateAsync({ phone: `7${phone}` }); + await sendCodeMutation.mutateAsync({ phone: `7${phone}` }); setResendSeconds(60); setStep("code"); setTimeout(() => { codeInputRefs.current[0]?.focus(); }, 100); - } catch { - setError("Не удалось отправить код. Попробуйте позже."); + } catch (err) { + setError(err instanceof Error ? err.message : "Не удалось отправить код. Попробуйте позже."); } }; @@ -142,8 +142,8 @@ export default function AuthDialog({ isOpen, onClose }: AuthDialogProps) { code: fullCode, }); onClose(); - } catch { - setError("Неверный код. Попробуйте ещё раз."); + } catch (err) { + setError(err instanceof Error ? err.message : "Неверный код. Попробуйте ещё раз."); } }; diff --git a/src/hooks/useApiClient.ts b/src/hooks/useApiClient.ts index 6c66892..5943ea7 100644 --- a/src/hooks/useApiClient.ts +++ b/src/hooks/useApiClient.ts @@ -35,6 +35,18 @@ const useApiClient = () => { console.error("Authentication error:", error); authPopup.open(); } + if (error.response?.status === 400 || error.response?.status === 429) { + const data = error.response?.data; + const message = + typeof data === "object" && data !== null + ? (data.message ?? data.error ?? data.detail ?? data.msg) + : typeof data === "string" + ? data + : undefined; + if (message && typeof message === "string") { + return Promise.reject(new Error(message)); + } + } return Promise.reject(error); } );