feat: simple impl

This commit is contained in:
2025-08-04 07:50:13 +03:00
parent a92c43ab1b
commit a812e650ce
21 changed files with 1800 additions and 58 deletions

View File

@ -4,11 +4,14 @@ import { FC, useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import { Button, Stack } from "@mantine/core";
import { useForm } from "@mantine/form";
import { Auth } from "@/client";
import PhoneInput from "@/components/PhoneInput/PhoneInput";
import { useAppDispatch } from "@/lib/store";
import { setLoginChallenge, setPhoneNumber } from "@/lib/features/auth/authSlice";
import { AuthService } from "@/mocks/authService";
import {
setLoginChallenge,
setPhoneNumber,
} from "@/lib/features/auth/authSlice";
import { notifications } from "@/lib/notifications";
import { useAppDispatch } from "@/lib/store";
type LoginForm = {
phoneNumber: string;
@ -39,21 +42,39 @@ const LoginForm: FC<Props> = ({ loginChallenge, isCreatingId = false }) => {
}, [loginChallenge]);
const handleSubmit = (values: LoginForm) => {
dispatch(setPhoneNumber(values.phoneNumber));
new AuthService().requestLogin(values.phoneNumber)
const phoneNumber = values.phoneNumber.replace(/ /g, "");
dispatch(setPhoneNumber(phoneNumber));
Auth.postAuthOtpRequest({
body: { phone_number: phoneNumber },
})
.then(response => response.data)
.then(({ ok, message }) => {
if (!ok) {
notifications.error({ message });
} else {
.then(response => {
console.log(response);
if (!response) {
notifications.error({
message: "Ошибка при отправке запроса",
});
return;
}
const { ok, message } = response;
notifications.guess(ok, { message });
if (ok) {
router.push("/verify-phone");
}
})
.catch(error => {
console.error(error);
notifications.error({ message: error.toString() });
})
});
// new AuthService().requestLogin(values.phoneNumber)
// .then(response => response.data)
// .then(({ ok, message }) => {
// if (!ok) {
// notifications.error({ message });
// } else {
// router.push("/verify-phone");
// }
// })
// .catch(error => {
// console.error(error);
// notifications.error({ message: error.toString() });
// })
};
const navigateToCreateId = () => router.push("/create-id");