feat(form/auth): validate existing email and surface mapped field errors#21
Merged
feat(form/auth): validate existing email and surface mapped field errors#21
Conversation
- TextField: aggregate validation messages from both meta.errors
and meta.errorMap, compute isInvalid from the combined list,
and pass unified allErrors to FieldError so mapped errors are shown
alongside standard errors.
- SignUpForm: make submit handler async and check whether the provided
email already exists before mutating; if it does, set a field
meta.errorMap entry ("onSubmit") for the email field to halt submit
and show the specific server-side validation error.
- Auth actions: add checkEmailExists server function with input
validation (zod) and a db lookup to indicate if an email is already
registered. Exported alongside existing auth helpers.
Why:
- Ensure server-side or mapped validation messages are surfaced in the
UI (previously only meta.errors were shown) so users see accurate
feedback.
- Prevent duplicate registrations by checking email existence during
sign-up and providing a clear field-level error instead of failing
silently or returning a generic error.
Greptile SummaryEnhanced form validation to surface server-side and mapped errors alongside standard validation errors, and added duplicate email detection during sign-up. Key changes:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant SignUpForm
participant TextField
participant checkEmailExists
participant Database
participant authClient
User->>SignUpForm: Fill form & submit
SignUpForm->>SignUpForm: Validate with signUpSchema
alt Validation fails
SignUpForm->>TextField: Show meta.errors
TextField->>User: Display validation errors
else Validation passes
SignUpForm->>checkEmailExists: Check email existence
checkEmailExists->>checkEmailExists: Validate input (z.email())
checkEmailExists->>Database: Query user by email
Database-->>checkEmailExists: Return user or null
alt Email exists
checkEmailExists-->>SignUpForm: { exists: true }
SignUpForm->>SignUpForm: Set errorMap["onSubmit"]
SignUpForm->>TextField: Update with errorMap
TextField->>TextField: Aggregate meta.errors + errorMap
TextField->>User: Display "Email already registered"
else Email available
checkEmailExists-->>SignUpForm: { exists: false }
SignUpForm->>authClient: signUp.email()
authClient-->>SignUpForm: Success/Error
alt Success
SignUpForm->>User: Navigate to dashboard
else Error
SignUpForm->>User: Show toast error
end
end
end
|
Comment on lines
73
to
74
| const parsedValue = signUpSchema.safeParse(value); | ||
| const email = parsedValue.data?.email; |
There was a problem hiding this comment.
style: Redundant validation - the form already validates with signUpSchema on line 66, so value is guaranteed to be valid here. You can directly use value.email instead of calling safeParse again.
Suggested change
| const parsedValue = signUpSchema.safeParse(value); | |
| const email = parsedValue.data?.email; | |
| const email = value.email; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/features/auth/components/sign-up-form.tsx
Line: 73:74
Comment:
**style:** Redundant validation - the form already validates with `signUpSchema` on line 66, so `value` is guaranteed to be valid here. You can directly use `value.email` instead of calling `safeParse` again.
```suggestion
const email = value.email;
```
How can I resolve this? If you propose a fix, please make it concise.a50c2d4 to
d331e62
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
and meta.errorMap, compute isInvalid from the combined list,
and pass unified allErrors to FieldError so mapped errors are shown
alongside standard errors.
email already exists before mutating; if it does, set a field
meta.errorMap entry ("onSubmit") for the email field to halt submit
and show the specific server-side validation error.
validation (zod) and a db lookup to indicate if an email is already
registered. Exported alongside existing auth helpers.
Why:
UI (previously only meta.errors were shown) so users see accurate
feedback.
sign-up and providing a clear field-level error instead of failing
silently or returning a generic error.