Enhance user verification and data validation features

- Updated `next.config.ts` to include remote image patterns for user verification.
- Introduced `VerifyUserDetails` function in `lib/person.ts` to validate user data against national records.
- Added `usePerson` hook for fetching national data based on ID card.
- Enhanced `signup` and `signin` functions in `auth-actions.ts` to handle user verification status and send notifications for pending verifications.
- Refactored `VerifyUser` function in `user-actions.ts` to incorporate national data validation.
- Improved UI components in the user verification page to display both database and national information.
- Updated `InputReadOnly` component to support customizable label classes for better styling.

These changes improve the user verification process, ensuring data integrity and enhancing the overall user experience.
This commit is contained in:
2025-01-10 15:59:44 +05:00
parent 1a195d2307
commit ff0eae6ec4
12 changed files with 253 additions and 123 deletions

View File

@ -1,6 +1,8 @@
"use server";
import usePerson from "@/hooks/use-person";
import prisma from "@/lib/db";
import VerifyUserDetails from "@/lib/person";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { CreateClient } from "./ninja/client";
@ -18,33 +20,42 @@ export async function VerifyUser(userId: string) {
if (!user) {
throw new Error("User not found");
}
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: "",
},
});
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");
}