fix(auth): show "account already exists" on duplicate email signup#4855
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview This change adds a Reviewed by Cursor Bugbot for commit cc005e5. Configure here. |
Greptile SummaryThis PR fixes a UX regression introduced by the better-auth 1.3.12→1.6.11 upgrade: when
Confidence Score: 5/5Safe to merge — the change is a narrow, well-gated pre-create check that only runs on an exact path match and only adds a SELECT before better-auth's normal flow. The hook is correctly scoped with an exact path equality check, the DB query is minimal (SELECT id only, LIMIT 1), email normalization matches better-auth's own convention, and the error code wires directly into the existing client-side handler. The acknowledged edge cases (Gmail dot/+ aliases, concurrent submissions) still fail safely at the DB unique constraint. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client as Signup Form
participant Hook as before Hook
participant DB as Database
participant BA as better-auth
Client->>Hook: "POST /sign-up/email {email, password}"
Note over Hook: path === '/sign-up/email' && body.email?
Hook->>DB: "SELECT id FROM user WHERE email = email.toLowerCase() LIMIT 1"
alt Email already exists
DB-->>Hook: [existingUser]
Hook-->>Client: APIError UNPROCESSABLE_ENTITY / USER_ALREADY_EXISTS
Note over Client: Shows "An account with this email already exists."
else Email is new
DB-->>Hook: []
Hook->>BA: continue to better-auth sign-up logic
BA->>DB: INSERT user (enforced by DB unique constraint)
BA-->>Client: Success / redirect to /verify
end
Reviews (2): Last reviewed commit: "fix(auth): use exact path match for dupl..." | Re-trigger Greptile |
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit cc005e5. Configure here.
Summary
requireEmailVerificationis on — so the signup form's existingUSER_ALREADY_EXISTShandler never fired and the user was silently routed to/verifywith no code (looked like "it took over the first account")beforehook: for/sign-up/email, if the email already exists, throwUSER_ALREADY_EXISTSso the inline "An account with this email already exists. Please sign in instead." message showsEMAIL_VERIFICATION_ENABLEDso behavior is uniform across environmentsNotes
uniqueon bothemailandnormalized_email. This is a UX-consistency fix; the check mirrors better-auth's ownemail.toLowerCase()lookup+alias (only withSIGNUP_EMAIL_VALIDATION_ENABLED) and true concurrent-submit races still fall to the DB unique constraint (correct outcome, generic error) rather than the inline messageType of Change
Testing
Tested manually: with email verification enabled, signing up with an existing email now shows "An account with this email already exists. Please sign in instead." instead of routing to the verify screen.
Checklist