Skip to content

Davidgu/safeguard for email/password jwt generation route - #233

Merged
llam36 merged 2 commits into
mainfrom
davidgu/safeguard_for_email/password_jwt_generation_route
Apr 2, 2026
Merged

llam36 merged 2 commits into
mainfrom
davidgu/safeguard_for_email/password_jwt_generation_route

Conversation

@shaply

@shaply shaply commented Nov 16, 2025

Copy link
Copy Markdown
Contributor

Not a huge concern, but there currently isn't a guardrail for valid email/password but deleted user entry. The exception is still caught before returning to the user, but not before emitting an error metric in Sentry.

Fix

  • Add safeguard for invalid user when performing lookup via prisma in authenticate

Testing

  • Additional test in DB Service validating authenticate correctly catches invalid prisma return
    Created the test in Auth-service.

authenticate now no longer logs a not found error and logs any other error from db service and throws an unknown error when that happens.

…t found in database, and also added a test to make sure NOT_FOUND is thrown when user isn't found in DB-service
…or is unknown for anything but the not found and it logs the error message to sentry
@greptile-apps

greptile-apps Bot commented Nov 16, 2025

Copy link
Copy Markdown
Contributor

Disclaimer: This comment was AI-generated and is not necessarily completely accurate. Please take code comments with a grain of salt.

Greptile Summary

  • Improved error handling in authenticate to differentiate expected NOT_FOUND errors (invalid/deleted users) from unexpected errors, preventing unnecessary Sentry alerts
  • Added comprehensive test coverage for deleted user authentication in both auth-service and db-service test suites

Confidence Score: 4/5

  • This PR is safe to merge with low risk
  • The changes improve error handling by preventing unnecessary Sentry logging for expected authentication failures. The logic correctly differentiates between NOT_FOUND (expected) and other errors (unexpected). However, there's a potential edge case where getUser at line 62-66 could fail if a user is deleted between password verification and final user retrieval, but this race condition is unlikely and would be caught by existing error handling.
  • No files require special attention

Important Files Changed

Filename Overview
packages/auth-service/src/modules/user/user.controller.ts Improved error handling to differentiate NOT_FOUND from unexpected errors, preventing unnecessary Sentry logs for expected authentication failures

Sequence Diagram

sequenceDiagram
    participant User
    participant AuthService
    participant DBService
    
    User->>AuthService: authenticate(email, password)
    AuthService->>DBService: getUserPasswordHash(email)
    alt User not found or deleted
        DBService-->>AuthService: NOT_FOUND error
        AuthService-->>User: NOT_FOUND error
    else User exists
        DBService-->>AuthService: passwordHash
        AuthService->>AuthService: bcrypt.compare(password, hash)
        alt Password incorrect
            AuthService-->>User: PERMISSION_DENIED error
        else Password correct
            AuthService->>DBService: getUser(email)
            DBService-->>AuthService: User object
            AuthService-->>User: User object
        end
    end
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format

@shaply
shaply requested a review from llam36 February 1, 2026 16:05
@shaply shaply linked an issue Feb 1, 2026 that may be closed by this pull request
2 tasks

@llam36 llam36 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@llam36
llam36 merged commit c85e833 into main Apr 2, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add safeguard for email/password jwt generation route

2 participants