signup
This commit is contained in:
@@ -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.";
|
||||
|
||||
@@ -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" },
|
||||
|
||||
Reference in New Issue
Block a user