mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 10:04:44 +00:00
Refactor authentication and account management with modular UI components (#242)
This commit is contained in:
48
web/frontend/app/features/account/schemas.ts
Normal file
48
web/frontend/app/features/account/schemas.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const updateUsernameSchema = z.object({
|
||||
newUsername: z
|
||||
.string()
|
||||
.min(3, 'Username must be at least 3 characters')
|
||||
.max(64, 'Username must be at most 64 characters')
|
||||
.regex(/^[a-zA-Z0-9._-]+$/, 'Only letters, numbers, dots, underscores, and hyphens'),
|
||||
});
|
||||
|
||||
export type UpdateUsernameSchema = z.infer<typeof updateUsernameSchema>;
|
||||
|
||||
export const updateEmailSchema = z.object({
|
||||
newEmail: z.string().email('Invalid email address').max(128, 'Email is too long'),
|
||||
});
|
||||
|
||||
export type UpdateEmailSchema = z.infer<typeof updateEmailSchema>;
|
||||
|
||||
export const updateProfileSchema = z.object({
|
||||
firstName: z.string().min(1, 'First name is required').max(128, 'First name is too long'),
|
||||
lastName: z.string().min(1, 'Last name is required').max(128, 'Last name is too long'),
|
||||
dateOfBirth: z.string().min(1, 'Date of birth is required'),
|
||||
});
|
||||
|
||||
export type UpdateProfileSchema = z.infer<typeof updateProfileSchema>;
|
||||
|
||||
export const updatePasswordSchema = z
|
||||
.object({
|
||||
currentPassword: z.string().min(1, 'Current password is required'),
|
||||
newPassword: z
|
||||
.string()
|
||||
.min(8, 'Password must be at least 8 characters')
|
||||
.regex(/[A-Z]/, 'Password must contain an uppercase letter')
|
||||
.regex(/[a-z]/, 'Password must contain a lowercase letter')
|
||||
.regex(/[0-9]/, 'Password must contain a number')
|
||||
.regex(/[^a-zA-Z0-9]/, 'Password must contain a special character'),
|
||||
confirmNewPassword: z.string().min(1, 'Please confirm your new password'),
|
||||
})
|
||||
.refine((data) => data.newPassword === data.confirmNewPassword, {
|
||||
message: 'Passwords must match',
|
||||
path: ['confirmNewPassword'],
|
||||
})
|
||||
.refine((data) => data.newPassword !== data.currentPassword, {
|
||||
message: 'New password must be different from the current password',
|
||||
path: ['newPassword'],
|
||||
});
|
||||
|
||||
export type UpdatePasswordSchema = z.infer<typeof updatePasswordSchema>;
|
||||
Reference in New Issue
Block a user