mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-10-05 09:55:25 +00:00
fix: verification response handling 🐛
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 12m34s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 12m34s
This commit is contained in:
@@ -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);
|
||||
|
@@ -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",
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user