fix(auth): correct field highlighting on login and signup errors#1063
Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
📝 WalkthroughWalkthroughThe changes modify error handling and validation display in authentication routes. In Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@services/platform/app/routes/_auth/sign-up.tsx`:
- Around line 112-118: Introduce a small helper (e.g., mapSignupErrorToField or
determineSignupErrorField) that takes the signup error object (use
result.error.code and result.error.message) and returns the target form field
name ('email' for USER_ALREADY_EXISTS / message includes "already exists",
otherwise 'password'); replace the duplicated conditional in sign-up flow(s) so
both call this helper and then call form.setError(field, { message: errorMessage
}) to keep logic centralized and avoid drift.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: d9251307-f42b-436d-b219-9411016cf9ba
📒 Files selected for processing (2)
services/platform/app/routes/_auth/log-in.tsxservices/platform/app/routes/_auth/sign-up.tsx
💤 Files with no reviewable changes (1)
- services/platform/app/routes/_auth/log-in.tsx
| const errorMessage = | ||
| result.error.message || t('signup.wrongCredentials'); | ||
| const isUserExists = | ||
| result.error.code === 'USER_ALREADY_EXISTS' || | ||
| errorMessage.toLowerCase().includes('already exists'); | ||
| form.setError(isUserExists ? 'email' : 'password', { | ||
| message: errorMessage, |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Deduplicate signup error-field mapping to avoid drift.
The same “duplicate user → email, else password” logic appears in two places. Extracting a helper will keep both paths consistent.
♻️ Proposed refactor
+ const mapAuthErrorToField = (error: { code?: string; message?: string }) => {
+ const errorMessage = error.message || t('signup.wrongCredentials');
+ const isUserExists =
+ error.code === 'USER_ALREADY_EXISTS' ||
+ errorMessage.toLowerCase().includes('already exists');
+ return {
+ field: isUserExists ? 'email' : 'password',
+ message: errorMessage,
+ } as const;
+ };
onError: (ctx) => {
- const errorMessage =
- ctx.error.message || t('signup.wrongCredentials');
- const isUserExists =
- ctx.error.code === 'USER_ALREADY_EXISTS' ||
- errorMessage.toLowerCase().includes('already exists');
- form.setError(isUserExists ? 'email' : 'password', {
- message: errorMessage,
- });
+ const mapped = mapAuthErrorToField(ctx.error);
+ form.setError(mapped.field, { message: mapped.message });
},
if (result.error) {
signUpStartedRef.current = false;
- const errorMessage =
- result.error.message || t('signup.wrongCredentials');
- const isUserExists =
- result.error.code === 'USER_ALREADY_EXISTS' ||
- errorMessage.toLowerCase().includes('already exists');
- form.setError(isUserExists ? 'email' : 'password', {
- message: errorMessage,
- });
+ const mapped = mapAuthErrorToField(result.error);
+ form.setError(mapped.field, { message: mapped.message });
return;
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@services/platform/app/routes/_auth/sign-up.tsx` around lines 112 - 118,
Introduce a small helper (e.g., mapSignupErrorToField or
determineSignupErrorField) that takes the signup error object (use
result.error.code and result.error.message) and returns the target form field
name ('email' for USER_ALREADY_EXISTS / message includes "already exists",
otherwise 'password'); replace the duplicated conditional in sign-up flow(s) so
both call this helper and then call form.setError(field, { message: errorMessage
}) to keep logic centralized and avoid drift.
Summary
isInvalidfrom both email and password fields on login failure. The error message still displays below the form, but no field is highlighted — preventing information leakage about which credential is wrong.Fixes #952, fixes #954
Summary by CodeRabbit