fix: авторизация
This commit is contained in:
parent
950e0f3964
commit
28a7e0105f
|
|
@ -51,7 +51,7 @@ export const useSendCode = () => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationKey: ["auth", "send-code"],
|
mutationKey: ["auth", "send-code"],
|
||||||
mutationFn: async (data: SendCodeDto) => {
|
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;
|
return response.data;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -66,7 +66,7 @@ export const useVerifyCode = () => {
|
||||||
mutationKey: ["auth", "verify-code"],
|
mutationKey: ["auth", "verify-code"],
|
||||||
mutationFn: async (data: VerifyCodeDto) => {
|
mutationFn: async (data: VerifyCodeDto) => {
|
||||||
const response = await client.post<VerifyCodeResponse>(
|
const response = await client.post<VerifyCodeResponse>(
|
||||||
"/auth/phone/verify-code",
|
"/auth/verify-code",
|
||||||
data
|
data
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,15 +81,15 @@ export default function AuthDialog({ isOpen, onClose }: AuthDialogProps) {
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// await sendCodeMutation.mutateAsync({ phone: `7${phone}` });
|
await sendCodeMutation.mutateAsync({ phone: `7${phone}` });
|
||||||
setResendSeconds(60);
|
setResendSeconds(60);
|
||||||
setStep("code");
|
setStep("code");
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
codeInputRefs.current[0]?.focus();
|
codeInputRefs.current[0]?.focus();
|
||||||
}, 100);
|
}, 100);
|
||||||
} catch {
|
} catch (err) {
|
||||||
setError("Не удалось отправить код. Попробуйте позже.");
|
setError(err instanceof Error ? err.message : "Не удалось отправить код. Попробуйте позже.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -142,8 +142,8 @@ export default function AuthDialog({ isOpen, onClose }: AuthDialogProps) {
|
||||||
code: fullCode,
|
code: fullCode,
|
||||||
});
|
});
|
||||||
onClose();
|
onClose();
|
||||||
} catch {
|
} catch (err) {
|
||||||
setError("Неверный код. Попробуйте ещё раз.");
|
setError(err instanceof Error ? err.message : "Неверный код. Попробуйте ещё раз.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,18 @@ const useApiClient = () => {
|
||||||
console.error("Authentication error:", error);
|
console.error("Authentication error:", error);
|
||||||
authPopup.open();
|
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);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue