mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-12 22:45:49 +00:00
90 lines
2.2 KiB
TypeScript
90 lines
2.2 KiB
TypeScript
"use server";
|
|
|
|
import { getServerSession } from "next-auth";
|
|
import { authOptions } from "@/app/auth";
|
|
import type { User, UserProfile } 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: {
|
|
// 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");
|
|
}
|
|
|
|
export async function getProfile() {
|
|
const session = await getServerSession(authOptions);
|
|
const response = await fetch(
|
|
`${process.env.SARLINK_API_BASE_URL}/api/auth/profile/`,
|
|
{
|
|
method: "GET",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
Authorization: `Token ${session?.apiToken}`,
|
|
},
|
|
},
|
|
);
|
|
|
|
return handleApiResponse<User>(response, "getProfile");
|
|
}
|
|
|
|
|
|
|
|
export async function getProfileById(userId: string) {
|
|
const session = await getServerSession(authOptions);
|
|
const response = await fetch(
|
|
`${process.env.SARLINK_API_BASE_URL}/api/auth/users/${userId}/`,
|
|
{
|
|
method: "GET",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
Authorization: `Token ${session?.apiToken}`,
|
|
},
|
|
},
|
|
);
|
|
|
|
return handleApiResponse<UserProfile>(response, "getProfilebyId");
|
|
}
|
|
|