mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-24 13:01:56 +00:00
chore: tweaks authFormSchema using zod validation for client side
This commit is contained in:
+39
-26
@@ -1,30 +1,43 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const authFormSchema = (type: string) =>
|
||||
z.object({
|
||||
// Sign Up
|
||||
companyName:
|
||||
type === "sign-in" ? z.string().optional() : z.string().min(3).optional(),
|
||||
firstName:
|
||||
type === "sign-in"
|
||||
? z.string().optional()
|
||||
: z
|
||||
.string()
|
||||
.min(3, {
|
||||
message: "The name must be at least 3 characters.",
|
||||
})
|
||||
.max(20),
|
||||
confirmPassword:
|
||||
type === "sign-in" ? z.string().optional() : z.string().min(6),
|
||||
termsAndConditions:
|
||||
type === "sign-in"
|
||||
? z.enum(["true"]).optional()
|
||||
: z.enum(["true"], {
|
||||
errorMap: () => ({
|
||||
message: "You must accept the terms and conditions.",
|
||||
z
|
||||
.object({
|
||||
// Sign Up
|
||||
companyName:
|
||||
type === "sign-in"
|
||||
? z.string().optional()
|
||||
: z.string().min(3).optional(),
|
||||
firstName:
|
||||
type === "sign-in"
|
||||
? z.string().optional()
|
||||
: z
|
||||
.string()
|
||||
.min(3, {
|
||||
message: "The name must be at least 3 characters.",
|
||||
})
|
||||
.max(20),
|
||||
confirmPassword:
|
||||
type === "sign-in"
|
||||
? z.string().optional()
|
||||
: z.string().min(3, {
|
||||
message: "It must contain at least 12 characters.",
|
||||
}),
|
||||
}),
|
||||
// both
|
||||
email: z.string().email(),
|
||||
password: z.string().min(6),
|
||||
});
|
||||
termsAndConditions:
|
||||
type === "sign-in"
|
||||
? z.enum(["true"]).optional()
|
||||
: z.enum(["true"], {
|
||||
errorMap: () => ({
|
||||
message: "You must accept the terms and conditions.",
|
||||
}),
|
||||
}),
|
||||
// Fields for Sign In and Sign Up
|
||||
email: z.string().email(),
|
||||
password: z.string().min(3, {
|
||||
message: "It must contain at least 12 characters.",
|
||||
}),
|
||||
})
|
||||
.refine((data) => data.password === data.confirmPassword, {
|
||||
message: "The password must match",
|
||||
path: ["confirmPassword"],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user