mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-01 21:28:23 +00:00
refactor: enhance authentication and signup flow with new providers, update middleware matcher, and improve type safety for API responses
This commit is contained in:
@ -1,11 +1,9 @@
|
||||
"use server";
|
||||
|
||||
import { VerifyUserDetails } from "@/lib/person";
|
||||
import { signUpFormSchema } from "@/lib/schemas";
|
||||
import { headers } from "next/headers";
|
||||
import { checkIdOrPhone } from "@/queries/authentication";
|
||||
import { redirect } from "next/navigation";
|
||||
import { z } from "zod";
|
||||
import { SendUserRejectionDetailSMS } from "./user-actions";
|
||||
const formSchema = z.object({
|
||||
phoneNumber: z
|
||||
.string()
|
||||
@ -84,33 +82,28 @@ export async function signup(_actionState: ActionState, formData: FormData) {
|
||||
};
|
||||
}
|
||||
|
||||
// const idCardExists = await prisma.user.findFirst({
|
||||
// where: {
|
||||
// id_card: parsedData.data.id_card,
|
||||
// },
|
||||
// });
|
||||
const idCardExists = await checkIdOrPhone({
|
||||
id_card: parsedData.data.id_card,
|
||||
});
|
||||
if (idCardExists.ok) {
|
||||
return {
|
||||
message: "ID card already exists.",
|
||||
payload: formData,
|
||||
db_error: "id_card",
|
||||
};
|
||||
}
|
||||
|
||||
// if (idCardExists) {
|
||||
// return {
|
||||
// message: "ID card already exists.",
|
||||
// payload: formData,
|
||||
// db_error: "id_card",
|
||||
// };
|
||||
// }
|
||||
const phoneNumberExists = await checkIdOrPhone({
|
||||
phone_number: parsedData.data.phone_number,
|
||||
});
|
||||
|
||||
// const phoneNumberExists = await prisma.user.findFirst({
|
||||
// where: {
|
||||
// phoneNumber: parsedData.data.phone_number,
|
||||
// },
|
||||
// });
|
||||
|
||||
// if (phoneNumberExists) {
|
||||
// return {
|
||||
// message: "Phone number already exists.",
|
||||
// payload: formData,
|
||||
// db_error: "phone_number",
|
||||
// };
|
||||
// }
|
||||
if (phoneNumberExists.ok) {
|
||||
return {
|
||||
message: "Phone number already exists.",
|
||||
payload: formData,
|
||||
db_error: "phone_number",
|
||||
};
|
||||
}
|
||||
|
||||
// const newUser = await prisma.user.create({
|
||||
// data: {
|
||||
@ -144,12 +137,12 @@ export async function signup(_actionState: ActionState, formData: FormData) {
|
||||
// `,
|
||||
// phoneNumber: process.env.ADMIN_PHONENUMBER ?? "",
|
||||
// });
|
||||
// return {
|
||||
// message:
|
||||
// "Your account has been requested for verification. Please wait for a response from admin.",
|
||||
// payload: formData,
|
||||
// db_error: "invalidPersonValidation",
|
||||
// };
|
||||
// return {
|
||||
// message:
|
||||
// "Your account has been requested for verification. Please wait for a response from admin.",
|
||||
// payload: formData,
|
||||
// db_error: "invalidPersonValidation",
|
||||
// };
|
||||
|
||||
// if (isValidPerson) {
|
||||
// await authClient.phoneNumber.sendOtp({
|
||||
@ -159,7 +152,7 @@ export async function signup(_actionState: ActionState, formData: FormData) {
|
||||
// redirect(
|
||||
// `/verify-otp?phone_number=${encodeURIComponent(newUser.phoneNumber)}`,
|
||||
// );
|
||||
// return { message: "User created successfully" };
|
||||
return { message: "User created successfully" };
|
||||
}
|
||||
|
||||
export const sendOtp = async (phoneNumber: string, code: string) => {
|
||||
|
Reference in New Issue
Block a user