diff --git a/apps/sim/app/(auth)/reset-password/reset-password-form.tsx b/apps/sim/app/(auth)/reset-password/reset-password-form.tsx index 0ff43b0561a..08ec08b65fc 100644 --- a/apps/sim/app/(auth)/reset-password/reset-password-form.tsx +++ b/apps/sim/app/(auth)/reset-password/reset-password-form.tsx @@ -97,49 +97,49 @@ export function SetNewPasswordForm({ }: SetNewPasswordFormProps) { const [password, setPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') - const [validationMessage, setValidationMessage] = useState('') + const [validationMessages, setValidationMessages] = useState([]) const [showPassword, setShowPassword] = useState(false) const [showConfirmPassword, setShowConfirmPassword] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() + const errors: string[] = [] + if (password.length < 8) { - setValidationMessage('Password must be at least 8 characters long') - return + errors.push('Password must be at least 8 characters long') } if (password.length > 100) { - setValidationMessage('Password must not exceed 100 characters') - return + errors.push('Password must not exceed 100 characters') } if (!/[A-Z]/.test(password)) { - setValidationMessage('Password must contain at least one uppercase letter') - return + errors.push('Password must contain at least one uppercase letter') } if (!/[a-z]/.test(password)) { - setValidationMessage('Password must contain at least one lowercase letter') - return + errors.push('Password must contain at least one lowercase letter') } if (!/[0-9]/.test(password)) { - setValidationMessage('Password must contain at least one number') - return + errors.push('Password must contain at least one number') } if (!/[^A-Za-z0-9]/.test(password)) { - setValidationMessage('Password must contain at least one special character') - return + errors.push('Password must contain at least one special character') } if (password !== confirmPassword) { - setValidationMessage('Passwords do not match') + errors.push('Passwords do not match') + } + + if (errors.length > 0) { + setValidationMessages(errors) return } - setValidationMessage('') + setValidationMessages([]) onSubmit(password) } @@ -162,7 +162,10 @@ export function SetNewPasswordForm({ onChange={(e) => setPassword(e.target.value)} required placeholder='Enter new password' - className={cn('pr-10', validationMessage && 'border-red-500 focus:border-red-500')} + className={cn( + 'pr-10', + validationMessages.length > 0 && 'border-red-500 focus:border-red-500' + )} />