mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-02 09:48:22 +00:00
registration verification WIP
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m40s
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m40s
This commit is contained in:
@ -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",
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user