mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-03 06:48:21 +00:00
refactor: update authentication flow to use NextAuth, replace better-auth with axios for API calls, and clean up unused code
This commit is contained in:
@ -1,85 +1,79 @@
|
||||
"use server";
|
||||
|
||||
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";
|
||||
|
||||
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");
|
||||
// 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 Rejectuser({
|
||||
userId,
|
||||
reason,
|
||||
}: { userId: string; reason: string }) {
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
});
|
||||
if (!user) {
|
||||
throw new Error("User not found");
|
||||
}
|
||||
// const user = await prisma.user.findUnique({
|
||||
// where: {
|
||||
// id: userId,
|
||||
// },
|
||||
// });
|
||||
// if (!user) {
|
||||
// throw new Error("User not found");
|
||||
// }
|
||||
|
||||
await SendUserRejectionDetailSMS({
|
||||
details: reason,
|
||||
phoneNumber: user.phoneNumber,
|
||||
});
|
||||
await prisma.user.delete({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
});
|
||||
// await SendUserRejectionDetailSMS({
|
||||
// details: reason,
|
||||
// phoneNumber: user.phoneNumber,
|
||||
// });
|
||||
// await prisma.user.delete({
|
||||
// where: {
|
||||
// id: userId,
|
||||
// },
|
||||
// });
|
||||
revalidatePath("/users");
|
||||
redirect("/users");
|
||||
}
|
||||
@ -117,13 +111,13 @@ export async function AddDevice({
|
||||
mac_address,
|
||||
user_id,
|
||||
}: { name: string; mac_address: string; user_id: string }) {
|
||||
const newDevice = await prisma.device.create({
|
||||
data: {
|
||||
name: name,
|
||||
mac: mac_address,
|
||||
userId: user_id,
|
||||
},
|
||||
});
|
||||
// const newDevice = await prisma.device.create({
|
||||
// data: {
|
||||
// name: name,
|
||||
// mac: mac_address,
|
||||
// userId: user_id,
|
||||
// },
|
||||
// });
|
||||
revalidatePath("/devices");
|
||||
return newDevice;
|
||||
// return newDevice;
|
||||
}
|
||||
|
Reference in New Issue
Block a user