Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | 4x 4x 15x 4x 4x 6x | import { z } from 'zod';
import { AUTH_ERROR_MESSAGES, PASSWORD_VALIDATION } from '@/constants/auth';
// Sign in form schema
export const signinSchema = z.object({
email: z
.string()
.min(1, AUTH_ERROR_MESSAGES.EMAIL_REQUIRED)
.email('Please enter a valid email address'),
password: z.string().min(1, AUTH_ERROR_MESSAGES.PASSWORD_REQUIRED),
});
// Sign up form schema
export const signupSchema = z
.object({
email: z
.string()
.min(1, AUTH_ERROR_MESSAGES.EMAIL_REQUIRED)
.email('Please enter a valid email address'),
password: z
.string()
.min(1, AUTH_ERROR_MESSAGES.PASSWORD_REQUIRED)
.min(
PASSWORD_VALIDATION.MIN_LENGTH,
`Password must be at least ${PASSWORD_VALIDATION.MIN_LENGTH} characters long`
)
.regex(
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)/,
AUTH_ERROR_MESSAGES.WEAK_PASSWORD
),
confirmPassword: z.string().min(1, 'Please confirm your password'),
})
.refine(data => data.password === data.confirmPassword, {
message: AUTH_ERROR_MESSAGES.PASSWORDS_DONT_MATCH,
path: ['confirmPassword'],
});
// Forgot password schema
export const forgotPasswordSchema = z.object({
email: z
.string()
.min(1, AUTH_ERROR_MESSAGES.EMAIL_REQUIRED)
.email('Please enter a valid email address'),
});
// Reset password schema
export const resetPasswordSchema = z
.object({
password: z
.string()
.min(1, AUTH_ERROR_MESSAGES.PASSWORD_REQUIRED)
.min(
PASSWORD_VALIDATION.MIN_LENGTH,
`Password must be at least ${PASSWORD_VALIDATION.MIN_LENGTH} characters long`
)
.regex(
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)/,
AUTH_ERROR_MESSAGES.WEAK_PASSWORD
),
confirmPassword: z.string().min(1, 'Please confirm your password'),
})
.refine(data => data.password === data.confirmPassword, {
message: AUTH_ERROR_MESSAGES.PASSWORDS_DONT_MATCH,
path: ['confirmPassword'],
});
// Type definitions for form data
export type SigninFormData = z.infer<typeof signinSchema>;
export type SignupFormData = z.infer<typeof signupSchema>;
export type ForgotPasswordFormData = z.infer<typeof forgotPasswordSchema>;
export type ResetPasswordFormData = z.infer<typeof resetPasswordSchema>;
|