diff --git a/src/components/auth/SignUpForm.tsx b/src/components/auth/SignUpForm.tsx index 465a249..134cd71 100644 --- a/src/components/auth/SignUpForm.tsx +++ b/src/components/auth/SignUpForm.tsx @@ -76,16 +76,13 @@ export default function SignUpForm() { try { setLoading(true); - // 1. Gọi hàm VERIFYOTP const verifyRes = await apiVerifyOTP(formData.email, otp); - - // Giả sử backend trả về token_id khi verify thành công - const tokenId = verifyRes?.token_id; + + const tokenId = verifyRes?.data?.token_id; if (!tokenId) { throw new Error("OTP không hợp lệ hoặc không có token_id"); } - // 2. Tạo payload và gọi hàm SIGNUP const signupPayload = { display_name: `${formData.fname} ${formData.lname}`.trim(), email: formData.email, @@ -95,10 +92,10 @@ export default function SignUpForm() { const signupRes = await apiSignUp(signupPayload); - // Thành công thì chuyển hướng hoặc thông báo console.log("Đăng ký thành công!", signupRes); alert("Đăng ký thành công! Đang chuyển hướng..."); - // window.location.href = '/signin'; // Chuyển hướng người dùng + + window.location.href = '/signin'; // Chuyển hướng người dùng } catch (error) { const errorMessage = error instanceof Error ? error.message : "Xác thực OTP hoặc đăng ký thất bại."; diff --git a/src/service/auth.ts b/src/service/auth.ts index a8bcc10..d2f5764 100644 --- a/src/service/auth.ts +++ b/src/service/auth.ts @@ -1,7 +1,7 @@ import { API } from "../../api"; export const apiCreateOTP = async (email : string) => { - const token_type = 1; + const token_type = 2; const response = await fetch(API.User.CREATEOTP, { method: "POST", headers: { "Content-Type": "application/json" }, @@ -10,10 +10,9 @@ export const apiCreateOTP = async (email : string) => { return response.json(); }; -export const apiVerifyOTP = async (email: string, otp: string) => { - - const body = { email, otp, token_type: 1 }; - +export const apiVerifyOTP = async (email: string, token: string) => { + const body = { email, token, token_type: 2 }; + console.log("Request Body for Verify OTP:", body); // Log body trước khi gửi yêu cầu const response = await fetch(API.User.VERIFYOTP, { method: "POST", headers: { "Content-Type": "application/json" },