Skip to content

Commit 4d553ca

Browse files
author
Theodore Li
committed
fix(signup): show multiple signup errors at once
1 parent 5ca66c3 commit 4d553ca

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

apps/sim/app/(auth)/reset-password/reset-password-form.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,38 +104,38 @@ export function SetNewPasswordForm({
104104
const handleSubmit = async (e: React.FormEvent) => {
105105
e.preventDefault()
106106

107+
const errors: string[] = []
108+
107109
if (password.length < 8) {
108-
setValidationMessage('Password must be at least 8 characters long')
109-
return
110+
errors.push('Password must be at least 8 characters long')
110111
}
111112

112113
if (password.length > 100) {
113-
setValidationMessage('Password must not exceed 100 characters')
114-
return
114+
errors.push('Password must not exceed 100 characters')
115115
}
116116

117117
if (!/[A-Z]/.test(password)) {
118-
setValidationMessage('Password must contain at least one uppercase letter')
119-
return
118+
errors.push('Password must contain at least one uppercase letter')
120119
}
121120

122121
if (!/[a-z]/.test(password)) {
123-
setValidationMessage('Password must contain at least one lowercase letter')
124-
return
122+
errors.push('Password must contain at least one lowercase letter')
125123
}
126124

127125
if (!/[0-9]/.test(password)) {
128-
setValidationMessage('Password must contain at least one number')
129-
return
126+
errors.push('Password must contain at least one number')
130127
}
131128

132129
if (!/[^A-Za-z0-9]/.test(password)) {
133-
setValidationMessage('Password must contain at least one special character')
134-
return
130+
errors.push('Password must contain at least one special character')
135131
}
136132

137133
if (password !== confirmPassword) {
138-
setValidationMessage('Passwords do not match')
134+
errors.push('Passwords do not match')
135+
}
136+
137+
if (errors.length > 0) {
138+
setValidationMessage(errors.join(' '))
139139
return
140140
}
141141

apps/sim/app/(auth)/signup/signup-form.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,12 @@ function SignupFormContent({
229229
errors.length > 0
230230
) {
231231
if (nameValidationErrors.length > 0) {
232-
setNameErrors([nameValidationErrors[0]])
233232
setShowNameValidationError(true)
234233
}
235234
if (emailValidationErrors.length > 0) {
236-
setEmailErrors([emailValidationErrors[0]])
237235
setShowEmailValidationError(true)
238236
}
239237
if (errors.length > 0) {
240-
setPasswordErrors([errors[0]])
241238
setShowValidationError(true)
242239
}
243240
setIsLoading(false)
@@ -400,7 +397,7 @@ function SignupFormContent({
400397
/>
401398
<div
402399
className={cn(
403-
'absolute right-0 left-0 z-10 grid transition-[grid-template-rows] duration-200 ease-out',
400+
'grid transition-[grid-template-rows] duration-200 ease-out',
404401
showNameValidationError && nameErrors.length > 0
405402
? 'grid-rows-[1fr]'
406403
: 'grid-rows-[0fr]'
@@ -438,7 +435,7 @@ function SignupFormContent({
438435
/>
439436
<div
440437
className={cn(
441-
'absolute right-0 left-0 z-10 grid transition-[grid-template-rows] duration-200 ease-out',
438+
'grid transition-[grid-template-rows] duration-200 ease-out',
442439
(showEmailValidationError && emailErrors.length > 0) ||
443440
(emailError && !showEmailValidationError)
444441
? 'grid-rows-[1fr]'
@@ -497,7 +494,7 @@ function SignupFormContent({
497494
</div>
498495
<div
499496
className={cn(
500-
'absolute right-0 left-0 z-10 grid transition-[grid-template-rows] duration-200 ease-out',
497+
'grid transition-[grid-template-rows] duration-200 ease-out',
501498
showValidationError && passwordErrors.length > 0
502499
? 'grid-rows-[1fr]'
503500
: 'grid-rows-[0fr]'

apps/sim/app/api/auth/reset-password/route.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ export async function POST(request: NextRequest) {
2626
const validationResult = resetPasswordSchema.safeParse(body)
2727

2828
if (!validationResult.success) {
29-
const firstError = validationResult.error.errors[0]
30-
const errorMessage = firstError?.message || 'Invalid request data'
29+
const errorMessage = validationResult.error.errors.map((e) => e.message).join(' ')
3130

3231
logger.warn('Invalid password reset request data', {
3332
errors: validationResult.error.format(),

0 commit comments

Comments
 (0)