feat(user-verification): implement user verification functionality and update dialog UI
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 6m54s

This commit is contained in:
2025-07-16 02:03:03 +05:00
parent 7a02cb2415
commit dc3b5f9bf9
2 changed files with 79 additions and 85 deletions

View File

@ -9,52 +9,43 @@ import type { ApiError } from "@/lib/backend-types";
import type { User } from "@/lib/types/user";
import { handleApiResponse } from "@/utils/tryCatch";
export async function VerifyUser(_userId: string) {
// const user = await prisma.user.findUnique({
// where: {
// id: userId,
// },
// include: {Rejectuser
// atoll: true,
// island: true,
// },
// });
// if (!user) {
// throw new Error("User not found");
// }
// const isValidPerson = await VerifyUserDetails({ user });
// if (!isValidPerson)
// throw new Error("The user details does not match national data.");
// if (isValidPerson) {
// await prisma.user.update({
// where: {
// id: userId,
// },
// data: {
// verified: true,
// },
// });
// const ninjaClient = await CreateClient({
// group_settings_id: "",
// address1: "",
// city: user.atoll?.name || "",
// state: user.island?.name || "",
// postal_code: "",
// country_id: "462",
// address2: user.address || "",
// contacts: {
// first_name: user.name?.split(" ")[0] || "",
// last_name: user.name?.split(" ")[1] || "",
// email: user.email || "",
// phone: user.phoneNumber || "",
// send_email: false,
// custom_value1: user.dob?.toISOString().split("T")[0] || "",
// custom_value2: user.id_card || "",
// custom_value3: "",
// },
// });
// }
// revalidatePath("/users");
type VerifyUserResponse = {
"ok": boolean,
"mismatch_fields": string[] | null,
"error": string | null,
"detail": string | null
} | {
"message": boolean,
};
export async function verifyUser(userId: string) {
const session = await getServerSession(authOptions);
if (!session?.apiToken) {
return { ok: false, error: 'Not authenticated' } as const;
}
try {
const r = await fetch(
`${process.env.SARLINK_API_BASE_URL}/api/auth/users/${userId}/verify/`,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: `Token ${session.apiToken}`,
},
},
);
const body = (await r.json().catch(() => ({}))) as VerifyUserResponse &
{ message?: string; detail?: string };
if (!r.ok) {
const msg = body?.message || body?.detail || 'User verification failed';
return { ok: false, error: msg, mismatch_fields: body?.mismatch_fields || null } as const;
}
return { ok: true, data: body } as const;
} catch (err) {
return { ok: false, error: (err as Error).message } as const;
}
}
export async function getProfile() {