flowstate/lib/schemas/auth.ts
Chneemann 3812afab5a
All checks were successful
Deploy Flowstate to VPS / deploy (push) Successful in 1m14s
feat(auth): integrate zod validation for login and registration
2026-08-23 10:37:14 +02:00

48 lines
1.3 KiB
TypeScript

/**
* @file lib/schemas/auth.ts
* @description Zod validation schemas for authentication forms, including login and user registration data constraints.
*/
import { z } from "zod";
/**
* Zod validation schema for user login credentials.
*/
export const loginSchema = z.object({
email: z
.string()
.max(255, "Email is too long")
.pipe(z.email("Please provide a valid email address")),
password: z
.string()
.min(1, "Password is required")
.max(72, "Password is too long"),
});
/**
* Zod validation schema for new user registration payloads, including password confirmation matching.
*/
export const registerSchema = z
.object({
firstName: z
.string()
.min(1, "First name is required")
.max(50, "First name is too long"),
lastName: z
.string()
.min(1, "Last name is required")
.max(50, "Last name is too long"),
email: z
.string()
.max(255, "Email is too long")
.pipe(z.email("Please provide a valid email address")),
password: z
.string()
.min(8, "Password must be at least 8 characters long")
.max(72, "Password is too long (max 72 characters)"),
confirmPassword: z.string(),
})
.refine((data) => data.password === data.confirmPassword, {
message: "Passwords do not match",
path: ["confirmPassword"],
});