diff --git a/actions/auth-actions.ts b/actions/auth-actions.ts index 961c3a3..d671073 100644 --- a/actions/auth-actions.ts +++ b/actions/auth-actions.ts @@ -15,6 +15,10 @@ export type FilterUserResponse = { ok: boolean; verified: boolean; }; +export type FilterTempUserResponse = { + ok: boolean; + otp_verified: boolean; +}; export async function signin(previousState: ActionState, formData: FormData) { const phoneNumber = formData.get("phoneNumber") as string; diff --git a/app/(auth)/auth/verify-otp-registration/page.tsx b/app/(auth)/auth/verify-otp-registration/page.tsx index d712bf4..ee6f497 100644 --- a/app/(auth)/auth/verify-otp-registration/page.tsx +++ b/app/(auth)/auth/verify-otp-registration/page.tsx @@ -1,5 +1,6 @@ import VerifyRegistrationOTPForm from "@/components/auth/verify-registration-otp-form"; -import { checkIdOrPhone } from "@/queries/authentication"; +import ClientErrorMessage from "@/components/client-error-message"; +import { checkIdOrPhone, checkTempIdOrPhone } from "@/queries/authentication"; import { tryCatch } from "@/utils/tryCatch"; import Image from "next/image"; import { redirect } from "next/navigation"; @@ -18,12 +19,14 @@ export default async function VerifyRegistrationOTP({ "phone number from server page params (verify otp page)", phone_number, ); - const [error, response] = await tryCatch(checkIdOrPhone({ phone_number })); + const [error, response] = await tryCatch( + checkTempIdOrPhone({ phone_number }), + ); if (error) { console.log("Error in checkIdOrPhone", error); - return redirect("/auth/signin"); + return ; } - if (response.verified) redirect("/auth/signin"); + if (response.otp_verified) redirect("/auth/signin"); return (
diff --git a/queries/authentication.ts b/queries/authentication.ts index 9052841..988955d 100644 --- a/queries/authentication.ts +++ b/queries/authentication.ts @@ -1,6 +1,7 @@ "use server"; import { type ActionState, + type FilterTempUserResponse, type FilterUserResponse, backendMobileLogin, } from "@/actions/auth-actions"; @@ -72,6 +73,23 @@ export async function checkIdOrPhone({ return data; } +export async function checkTempIdOrPhone({ + id_card, + phone_number, +}: { id_card?: string; phone_number?: string }) { + const response = await fetch( + `${process.env.SARLINK_API_BASE_URL}/api/auth/users/temp/filter/?id_card=${id_card}&mobile=${phone_number}`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }, + ); + const data = (await response.json()) as FilterTempUserResponse; + return data; +} + type TSignupUser = Pick< User, "username" | "address" | "mobile" | "id_card" | "dob"