diff --git a/src/app/api/auth/register/route.ts b/src/app/api/auth/register/route.ts index aca1c4d..c3713f6 100644 --- a/src/app/api/auth/register/route.ts +++ b/src/app/api/auth/register/route.ts @@ -12,7 +12,6 @@ import registerSchema from "@/validators/registerSchema"; async function handler(request: NextRequest): Promise { try { const data = await request.json(); - const validatedData = registerSchema.parse(data); const userData: RegisterUser = { diff --git a/src/components/form/Register.tsx b/src/components/form/Register.tsx index 49c703b..efad679 100644 --- a/src/components/form/Register.tsx +++ b/src/components/form/Register.tsx @@ -47,6 +47,7 @@ const Register = () => { await registerUserApi({ email: data.email, password: data.password, + confirmPassword: data.confirmPassword, username: data.username, name: data.name, lastName: data.lastName, diff --git a/src/validators/registerSchema.ts b/src/validators/registerSchema.ts index 9715a9d..67d5af7 100644 --- a/src/validators/registerSchema.ts +++ b/src/validators/registerSchema.ts @@ -19,29 +19,33 @@ const registerSchema = z .refine((value) => value.trim().length > 0, { message: "Ce champ est requis", }), - dateOfBirth: z - .string({ required_error: "Ce champ est requis" }) - .refine( - (val) => { - const date = new Date(val); - if (isNaN(date.getTime())) { - return false; - } - return true; - }, - { - message: "Date invalide", - }, - ) - .refine( - (val) => { - const date = new Date(val); - return date <= new Date(); - }, - { - message: "La date ne peut pas ĂȘtre dans le futur", - }, - ), + dateOfBirth: z.preprocess( + (val) => { + if (typeof val === "string") return val; + if (val instanceof Date) return val.toISOString(); + return ""; + }, + z + .string({ required_error: "Ce champ est requis" }) + .refine( + (val) => { + const date = new Date(val); + return !isNaN(date.getTime()); + }, + { + message: "Date invalide", + }, + ) + .refine( + (val) => { + const date = new Date(val); + return date <= new Date(); + }, + { + message: "La date ne peut pas ĂȘtre dans le futur", + }, + ), + ), email: z .string({ required_error: "Ce champ est requis" }) .email({ message: "Email invalide" })