registration verification WIP
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m40s

This commit is contained in:
2025-04-17 14:04:22 +05:00
parent 0f9d1107de
commit 470e8452b5
3 changed files with 83 additions and 44 deletions

View File

@ -1,7 +1,9 @@
"use server";
import type { ActionState } from "@/actions/auth-actions";
import type { TAuthUser, User } from "@/lib/types/user";
import axiosInstance from "@/utils/axiosInstance";
import { handleApiResponse } from "@/utils/tryCatch";
import { z } from "zod";
export async function login({
password,
@ -92,3 +94,59 @@ export async function backendRegister({ payload }: { payload: TSignupUser }) {
console.log("backendRegister response", response);
return handleApiResponse<{ t_username: string }>(response, "backendRegister");
}
const formSchema = z.object({
mobile: z.string().regex(/^[79]\d{6}$/, "Please enter a valid phone number"),
otp: z
.string()
.min(6, {
message: "OTP is required.",
})
.max(6, {
message: "OTP is required.",
}),
});
export async function VerifyRegistrationOTP(
_actionState: ActionState,
formData: FormData,
) {
const formValues = Object.fromEntries(formData.entries());
const result = formSchema.safeParse(formValues);
console.log("formValues", formValues);
if (!result.success) {
return {
message: result.error.errors[0].message, // Get the error message from Zod
status: "error",
};
}
if (formValues.otp === "") {
return {
message: "OTP is required.",
status: "error",
};
}
const { mobile, otp } = formValues;
const response = await fetch(
`${process.env.SARLINK_API_BASE_URL}/api/auth/register/verify/`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
mobile: mobile,
otp: Number.parseInt(otp as string),
}),
},
);
const data = (await response.json()) as { message: string };
return {
message: data.message,
status: response.status === 200 ? "success" : "error",
};
}