feat: implement user registration and OTP verification flow with backend integration
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m29s

This commit is contained in:
2025-04-17 13:02:35 +05:00
parent de1e842145
commit 0f9d1107de
5 changed files with 189 additions and 29 deletions

View File

@ -1,6 +1,7 @@
"use server";
import type { TAuthUser } from "@/lib/types/user";
import type { TAuthUser, User } from "@/lib/types/user";
import axiosInstance from "@/utils/axiosInstance";
import { handleApiResponse } from "@/utils/tryCatch";
export async function login({
password,
@ -51,7 +52,6 @@ export async function checkIdOrPhone({
id_card,
phone_number,
}: { id_card?: string; phone_number?: string }) {
console.log("id_card and phone_number", { id_card, phone_number });
const response = await fetch(
`${process.env.SARLINK_API_BASE_URL}/api/auth/users/filter/?id_card=${id_card}&mobile=${phone_number}`,
{
@ -64,3 +64,31 @@ export async function checkIdOrPhone({
const data = await response.json();
return data;
}
type TSignupUser = Pick<
User,
"username" | "address" | "mobile" | "id_card" | "dob"
> & {
firstname: string;
lastname: string;
atoll: number;
island: number;
acc_no: string;
terms_accepted: boolean;
policy_accepted: boolean;
};
export async function backendRegister({ payload }: { payload: TSignupUser }) {
console.log("backendRegister payload", payload);
const response = await fetch(
`${process.env.SARLINK_API_BASE_URL}/api/auth/register/`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
},
);
console.log("backendRegister response", response);
return handleApiResponse<{ t_username: string }>(response, "backendRegister");
}