fix: verification response handling 🐛
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 12m34s

This commit is contained in:
2025-09-15 22:00:57 +05:00
parent 17aa65a686
commit c67b8ade10
2 changed files with 351 additions and 366 deletions

View File

@@ -1,5 +1,7 @@
"use server"; "use server";
import { redirect } from "next/navigation";
import { z } from "zod";
import { signUpFormSchema } from "@/lib/schemas"; import { signUpFormSchema } from "@/lib/schemas";
import { import {
backendRegister, backendRegister,
@@ -7,8 +9,7 @@ import {
checkTempIdOrPhone, checkTempIdOrPhone,
} from "@/queries/authentication"; } from "@/queries/authentication";
import { handleApiResponse, tryCatch } from "@/utils/tryCatch"; import { handleApiResponse, tryCatch } from "@/utils/tryCatch";
import { redirect } from "next/navigation";
import { z } from "zod";
const formSchema = z.object({ const formSchema = z.object({
phoneNumber: z phoneNumber: z
.string() .string()
@@ -22,9 +23,10 @@ export type FilterUserResponse = {
export type FilterTempUserResponse = { export type FilterTempUserResponse = {
ok: boolean; ok: boolean;
otp_verified: boolean; otp_verified: boolean;
t_verified: boolean;
}; };
export async function signin(previousState: ActionState, formData: FormData) { export async function signin(_previousState: ActionState, formData: FormData) {
const phoneNumber = formData.get("phoneNumber") as string; const phoneNumber = formData.get("phoneNumber") as string;
const result = formSchema.safeParse({ phoneNumber }); const result = formSchema.safeParse({ phoneNumber });
console.log(phoneNumber); console.log(phoneNumber);

View File

@@ -1,15 +1,13 @@
"use server"; "use server";
import { import { z } from "zod";
type ActionState, import type {
type FilterTempUserResponse, ActionState,
type FilterUserResponse, FilterTempUserResponse,
backendMobileLogin, FilterUserResponse,
} from "@/actions/auth-actions"; } from "@/actions/auth-actions";
import type { TAuthUser, User } from "@/lib/types/user"; import type { TAuthUser, User } from "@/lib/types/user";
import axiosInstance from "@/utils/axiosInstance"; import axiosInstance from "@/utils/axiosInstance";
import { handleApiResponse, tryCatch } from "@/utils/tryCatch"; import { handleApiResponse } from "@/utils/tryCatch";
import { redirect } from "next/navigation";
import { z } from "zod";
export async function login({ export async function login({
password, password,
@@ -172,20 +170,11 @@ export async function VerifyRegistrationOTP(
}), }),
}, },
); );
const data = (await response.json()) as { message: string }; const responseJson = await response.json();
console.log("responseJson", responseJson);
const data = responseJson as { message: string; verified: boolean };
const [error, userVerified] = await tryCatch( if (data.verified) {
checkIdOrPhone({ phone_number: mobile as string }),
);
if (error) {
return {
message:
"There was an error fetching your account information. Please contact support.",
status: "user_check_error",
};
}
if (userVerified.verified) {
return { return {
message: message:
"Your account has been successfully verified! You may login now.", "Your account has been successfully verified! You may login now.",
@@ -204,15 +193,9 @@ export async function VerifyRegistrationOTP(
// redirect(`/auth/verify-otp?phone_number=${mobile}`); // redirect(`/auth/verify-otp?phone_number=${mobile}`);
// } // }
} }
if (data.message === "User created successfully.") {
return { return {
message: message:
"Your account could not be verified. Please wait for you verification to be processed.", "Your account could not be verified. Please wait for you verification to be processed.",
status: "verify_error", status: "verify_error",
}; };
} }
return {
message: data.message,
status: "otp_error",
};
}