Summary
Create a flexible schema factory that generates Zod schemas for password-based authentication with configurable identifier types.
Implementation
- Support email, username, and phone as identifier options
- Compile-time type safety with
as const arrays
- Custom validation schemas for each identifier type
- Default validation: email format, phone E.164, username string
Usage
// Email only
const schema = createPasswordIdentitySchema(['email'] as const);
// Multiple identifiers with custom validation
const schema = createPasswordIdentitySchema(['email', 'phone'] as const, {
phone: z.string().regex(/^\+1[0-9]{10}$/)
});
Related: User story 20250709_user-sign-up.md