feat: implement user registration functionality

- Created registerUser server action with email/password validation
- Implemented password hashing with bcrypt (10 rounds)
- Added email uniqueness check to prevent duplicate registrations
- Created session after successful registration using NextAuth
- Added comprehensive validation for email format and password length (min 8 chars)
- Added email and password validation utilities to lib/validation.ts
- Removed PrismaAdapter from auth.ts (using JWT sessions only)
- Added vitest testing framework and configuration
- Created comprehensive unit tests for registration functionality
- All tests passing (6/6)

Requirements covered: 1.1, 1.2, 1.3, 1.4, 1.5
This commit is contained in:
2025-12-02 00:03:23 +00:00
parent 174a6601b2
commit 70121982a0
8 changed files with 1661 additions and 6 deletions

View File

@@ -301,3 +301,46 @@ export function validateItemData(data: {
},
}
}
/**
* Validate email format
*/
export function validateEmail(email: string): ValidationResult {
const sanitized = sanitizeString(email)
if (!sanitized) {
return { isValid: false, error: 'Email is required' }
}
// Basic email regex pattern
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
if (!emailRegex.test(sanitized)) {
return { isValid: false, error: 'Invalid email format' }
}
if (sanitized.length > 255) {
return { isValid: false, error: 'Email must be less than 255 characters' }
}
return { isValid: true }
}
/**
* Validate password strength
*/
export function validatePassword(password: string): ValidationResult {
if (!password) {
return { isValid: false, error: 'Password is required' }
}
if (password.length < 8) {
return { isValid: false, error: 'Password must be at least 8 characters' }
}
if (password.length > 128) {
return { isValid: false, error: 'Password must be less than 128 characters' }
}
return { isValid: true }
}