signup
This commit is contained in:
@@ -76,16 +76,13 @@ export default function SignUpForm() {
|
|||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
// 1. Gọi hàm VERIFYOTP
|
|
||||||
const verifyRes = await apiVerifyOTP(formData.email, otp);
|
const verifyRes = await apiVerifyOTP(formData.email, otp);
|
||||||
|
|
||||||
// Giả sử backend trả về token_id khi verify thành công
|
const tokenId = verifyRes?.data?.token_id;
|
||||||
const tokenId = verifyRes?.token_id;
|
|
||||||
if (!tokenId) {
|
if (!tokenId) {
|
||||||
throw new Error("OTP không hợp lệ hoặc không có token_id");
|
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 = {
|
const signupPayload = {
|
||||||
display_name: `${formData.fname} ${formData.lname}`.trim(),
|
display_name: `${formData.fname} ${formData.lname}`.trim(),
|
||||||
email: formData.email,
|
email: formData.email,
|
||||||
@@ -95,10 +92,10 @@ export default function SignUpForm() {
|
|||||||
|
|
||||||
const signupRes = await apiSignUp(signupPayload);
|
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);
|
console.log("Đăng ký thành công!", signupRes);
|
||||||
alert("Đăng ký thành công! Đang chuyển hướng...");
|
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) {
|
} catch (error) {
|
||||||
const errorMessage = error instanceof Error ? error.message : "Xác thực OTP hoặc đăng ký thất bại.";
|
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";
|
import { API } from "../../api";
|
||||||
|
|
||||||
export const apiCreateOTP = async (email : string) => {
|
export const apiCreateOTP = async (email : string) => {
|
||||||
const token_type = 1;
|
const token_type = 2;
|
||||||
const response = await fetch(API.User.CREATEOTP, {
|
const response = await fetch(API.User.CREATEOTP, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
@@ -10,10 +10,9 @@ export const apiCreateOTP = async (email : string) => {
|
|||||||
return response.json();
|
return response.json();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const apiVerifyOTP = async (email: string, otp: string) => {
|
export const apiVerifyOTP = async (email: string, token: string) => {
|
||||||
|
const body = { email, token, token_type: 2 };
|
||||||
const body = { email, otp, token_type: 1 };
|
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, {
|
const response = await fetch(API.User.VERIFYOTP, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
|||||||
Reference in New Issue
Block a user