Repository navigation
fix(auth): prevent login and signup when user is already authenticated - #315
Merged
omegascorp merged 3 commits intoJul 27, 2026
Merged
omegascorp merged 3 commits into
omegascorp merged 3 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6176979. Configure here.
…authenticated users
Collaborator
|
@ankit-0903 looks good. Please resolve the conflicts |
Contributor
Author
|
Hi @omegascorp*, *
I have merged the latest 'main' branch and resolved the merge conflicts.
Additionally, I updated the authentication rejection checks to throw
'ValidationError' (returning HTTP 400 Bad Request) instead of 'AuthError'
(returning HTTP 401 Unauthorized). This prevents potential client-side
issues where global interceptors might treat a 401 as a session expiry and
log the user out unexpectedly.
All 861 unit tests are building and passing cleanly. Ready for another
review!
…On Wed, Jul 22, 2026 at 5:17 PM Hayk ***@***.***> wrote:
*omegascorp* left a comment (modelence/modelence#315)
<#315 (comment)>
@ankit-0903 <https://github.com/ankit-0903> looks good. Please resolve
the conflicts
—
Reply to this email directly, view it on GitHub
<#315?email_source=notifications&email_token=A3WGSJZN4KYFKGJBDIWI4I35GCSV5A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMBUGUZTSNBVGUZKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-5045394552>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A3WGSJ6UKBT7767AAOAPYPL5GCSV5AVCNFSNUABFKJSXA33TNF2G64TZHM4DIOBQGU3DKNBSHNEXG43VMU5TIOJSGE3DSNZWGQ4KC5QC>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/A3WGSJYIODWPZER3H5UOKYD5GCSV5A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMBUGUZTSNBVGUZKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y>
and Android
<https://github.com/notifications/mobile/android/A3WGSJ7RFAFHLOGEENILSBT5GCSV5A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMBUGUZTSNBVGUZKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>.
Download it today!
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
omegascorp
approved these changes
Jul 27, 2026
Contributor
Author
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.

What & Why
Currently,
handleLoginWithPasswordandhandleSignupWithPassworddo not reject requests from users who are already logged in until after performing IP rate limiting, argument validation, and disposable email checks.This PR moves the authentication check (
if (user)) to the very top of bothtryblocks to throw anAuthError('User is already authenticated', 'ALREADY_AUTHENTICATED')early. This prevents state overlaps, avoids duplicate rate-limit consumption, and skips unnecessary async checks.Closes #311
How it was tested
src/auth/login.test.tsandsrc/auth/signup.test.tsverifying that anAuthError(ALREADY_AUTHENTICATED) is thrown whenuseris in context and asserting that rate-limiting and disposable email checks are not called.npm run buildsucceeds.npx vitest run --fileParallelism=false).Note
Low Risk
Small, early-return guard in auth handlers with tests; no change to successful login/signup paths.
Overview
Password login and signup now fail fast when the request context already has an authenticated
user, instead of running rate limits and other checks first.Both
handleLoginWithPasswordandhandleSignupWithPasswordthrow aValidationErrorwith messageUser is already authenticatedand codeALREADY_AUTHENTICATEDimmediately after session validation (login) or at the start of the handler (signup). That avoids consuming sign-in/sign-up rate limits and skips disposable-email and DB lookups on signup when someone is already logged in.ValidationErrornow accepts an optionalcodein its constructor (aligned withAuthError), so clients can branch onALREADY_AUTHENTICATEDwithout string-matching messages.Unit tests assert the error shape and that rate limiting (and on signup, disposable checks and
findOne) are not invoked whenuseris present.Reviewed by Cursor Bugbot for commit 3f2d1a4. Bugbot is set up for automated code reviews on this repo. Configure here.