Skip to content

Commit

Permalink
Login step OTP
Browse files Browse the repository at this point in the history
  • Loading branch information
ntnhan90 committed Jan 3, 2024
1 parent 6a568b4 commit 49963a6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
32 changes: 26 additions & 6 deletions src/components/loginSteps/LoginComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useForm } from "react-hook-form";
import { server } from "../../utils/server";
import { useState } from "react";
import "react-phone-number-input/style.css";
import PhoneInput from "react-phone-number-input";
import { toast } from "react-toastify";
import { server } from "@utils/server";


type StepType = {
onChange: any;
Expand All @@ -18,16 +19,35 @@ const LoginComponent = ({ onChange, setPhone }: StepType) => {

const onSubmit = async () => {
var phone = value;
console.log(phone);
// console.log(phone);
setPhone(phone);
if (phone) {
if (phone.length == 12) {

phone = phone.substring(1);
//http://localhost:3010/web-customer/auth/request-otp

await fetch(`${server}web-customer/auth/request-otp`, {
method: "post",
mode: "cors",
cache: "no-cache",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
credentials: "include",
body: JSON.stringify({
phoneNumber: phone,
}),
})
.then((res) => res.json())
.then((json) => {
console.log(json);
})
.catch((error) => {
console.log(error);
});
toast.success(" Success!", { autoClose: 1500 });
setTimeout(() => {
onChange(2);
}, 3000);

} else {
toast.error(" Số điện thoại của bạn dường như chưa chính xác.", { autoClose: 1500 });
setError("Số điện thoại của bạn dường như chưa chính xác.");
Expand Down
4 changes: 3 additions & 1 deletion src/utils/server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const dev = process.env.NODE_ENV !== 'production';

export const server = dev ? 'http://localhost:3000/api/v1/' : 'http://localhost:3000/api/v1/';
//http://localhost:3010/web-customer/auth/request-otp

export const server = dev ? 'http://localhost:3010/' : 'http://localhost:3010';

0 comments on commit 49963a6

Please sign in to comment.