From 923887b5596189b017b4ddf7a40d8ecd69fb02ef Mon Sep 17 00:00:00 2001 From: i701 Date: Fri, 18 Apr 2025 14:35:34 +0500 Subject: [PATCH] feat: integrate checkTempIdOrPhone in signup logic to validate temporary phone numbers --- actions/auth-actions.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/actions/auth-actions.ts b/actions/auth-actions.ts index d671073..589fb42 100644 --- a/actions/auth-actions.ts +++ b/actions/auth-actions.ts @@ -1,7 +1,11 @@ "use server"; import { signUpFormSchema } from "@/lib/schemas"; -import { backendRegister, checkIdOrPhone } from "@/queries/authentication"; +import { + backendRegister, + checkIdOrPhone, + checkTempIdOrPhone, +} from "@/queries/authentication"; import { handleApiResponse, tryCatch } from "@/utils/tryCatch"; import { redirect } from "next/navigation"; import { z } from "zod"; @@ -133,7 +137,10 @@ export async function signup(_actionState: ActionState, formData: FormData) { phone_number: parsedData.data.phone_number, }); - if (phoneNumberExists.ok) { + const tempPhoneNumberExists = await checkTempIdOrPhone({ + phone_number: parsedData.data.phone_number, + }); + if (phoneNumberExists.ok || tempPhoneNumberExists.ok) { return { message: "Phone number already exists.", payload: formData, @@ -160,7 +167,11 @@ export async function signup(_actionState: ActionState, formData: FormData) { }), ); if (signupError) { - throw new Error(signupError.message); + return { + message: signupError.message, + payload: formData, + db_error: "phone_number", + }; } console.log("SIGNUP RESPONSE", signupResponse);