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";
import { redirect } from "next/navigation";
import { z } from "zod";
import { signUpFormSchema } from "@/lib/schemas";
import {
backendRegister,
@@ -7,8 +9,7 @@ import {
checkTempIdOrPhone,
} from "@/queries/authentication";
import { handleApiResponse, tryCatch } from "@/utils/tryCatch";
import { redirect } from "next/navigation";
import { z } from "zod";
const formSchema = z.object({
phoneNumber: z
.string()
@@ -22,9 +23,10 @@ export type FilterUserResponse = {
export type FilterTempUserResponse = {
ok: 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 result = formSchema.safeParse({ phoneNumber });
console.log(phoneNumber);

View File

@@ -1,15 +1,13 @@
"use server";
import {
type ActionState,
type FilterTempUserResponse,
type FilterUserResponse,
backendMobileLogin,
import { z } from "zod";
import type {
ActionState,
FilterTempUserResponse,
FilterUserResponse,
} from "@/actions/auth-actions";
import type { TAuthUser, User } from "@/lib/types/user";
import axiosInstance from "@/utils/axiosInstance";
import { handleApiResponse, tryCatch } from "@/utils/tryCatch";
import { redirect } from "next/navigation";
import { z } from "zod";
import { handleApiResponse } from "@/utils/tryCatch";
export async function login({
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(
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) {
if (data.verified) {
return {
message:
"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}`);
// }
}
if (data.message === "User created successfully.") {
return {
message:
"Your account could not be verified. Please wait for you verification to be processed.",
status: "verify_error",
};
}
return {
message: data.message,
status: "otp_error",
};
}