fix: авторизация
This commit is contained in:
parent
950e0f3964
commit
28a7e0105f
|
|
@ -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<VerifyCodeResponse>(
|
||||
"/auth/phone/verify-code",
|
||||
"/auth/verify-code",
|
||||
data
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -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 : "Неверный код. Попробуйте ещё раз.");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue