feat(01-03): add validation schemas and server actions
- Add Zod validation schemas for auth operations - Add server actions for register, login, reset, update password - Add clsx and tailwind-merge for class utilities - Password validation: 8+ chars, 1 number, 1 uppercase - Error messages in Italian per user requirement - Specific error messages (not generic 'invalid credentials') Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
39
src/lib/schemas/auth.ts
Normal file
39
src/lib/schemas/auth.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const registerSchema = z.object({
|
||||
email: z.string()
|
||||
.email('Email non valida'),
|
||||
password: z.string()
|
||||
.min(8, 'La password deve contenere almeno 8 caratteri')
|
||||
.regex(/[0-9]/, 'La password deve contenere almeno un numero')
|
||||
.regex(/[A-Z]/, 'La password deve contenere almeno una lettera maiuscola'),
|
||||
confirmPassword: z.string()
|
||||
}).refine((data) => data.password === data.confirmPassword, {
|
||||
message: 'Le password non coincidono',
|
||||
path: ['confirmPassword'],
|
||||
})
|
||||
|
||||
export const loginSchema = z.object({
|
||||
email: z.string().email('Email non valida'),
|
||||
password: z.string().min(1, 'Password richiesta'),
|
||||
})
|
||||
|
||||
export const resetPasswordSchema = z.object({
|
||||
email: z.string().email('Email non valida'),
|
||||
})
|
||||
|
||||
export const updatePasswordSchema = z.object({
|
||||
password: z.string()
|
||||
.min(8, 'La password deve contenere almeno 8 caratteri')
|
||||
.regex(/[0-9]/, 'La password deve contenere almeno un numero')
|
||||
.regex(/[A-Z]/, 'La password deve contenere almeno una lettera maiuscola'),
|
||||
confirmPassword: z.string()
|
||||
}).refine((data) => data.password === data.confirmPassword, {
|
||||
message: 'Le password non coincidono',
|
||||
path: ['confirmPassword'],
|
||||
})
|
||||
|
||||
export type RegisterInput = z.infer<typeof registerSchema>
|
||||
export type LoginInput = z.infer<typeof loginSchema>
|
||||
export type ResetPasswordInput = z.infer<typeof resetPasswordSchema>
|
||||
export type UpdatePasswordInput = z.infer<typeof updatePasswordSchema>
|
||||
Reference in New Issue
Block a user