Skip to content

Fix minor bug where invalid password triggered sentry - #229

Merged
UZ9 merged 1 commit into
mainfrom
ryder/invalid-pass-log
Nov 14, 2025
Merged

UZ9 merged 1 commit into
mainfrom
ryder/invalid-pass-log

Conversation

@UZ9

@UZ9 UZ9 commented Nov 14, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@greptile-apps

greptile-apps Bot commented Nov 14, 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 Overview

Greptile Summary

Added null check in getUserPasswordHash to prevent accessing properties on null user objects, fixing Sentry errors triggered during authentication with invalid credentials.

  • Fixed bug where getUserPasswordHash would attempt to access user.password when user is null
  • Now returns proper NOT_FOUND RpcException when user doesn't exist, matching pattern from getUser method
  • Added two test cases covering non-existent user scenarios (by email and by ID)
  • Prevents unhandled exceptions that were triggering Sentry alerts during normal authentication failures

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix follows existing patterns in the codebase (identical null check as in getUser), includes proper test coverage for both email and ID lookups, and addresses a real bug causing Sentry alerts
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/db-service/src/modules/user/user.controller.ts 5/5 Added null check for user lookup to prevent accessing null object properties
packages/db-service/test/user.e2e-spec.ts 5/5 Added comprehensive test coverage for non-existent user scenarios by email and ID

Sequence Diagram

sequenceDiagram
    participant Client
    participant AuthService
    participant DBService
    participant Database
    
    Client->>AuthService: authenticate(email, password)
    AuthService->>DBService: getUserPasswordHash(email)
    DBService->>Database: findUser(email)
    
    alt User Not Found (Fixed)
        Database-->>DBService: null
        DBService-->>AuthService: RpcException(NOT_FOUND)
        AuthService-->>Client: Error: No user found
    else User Found
        Database-->>DBService: user object
        DBService-->>AuthService: { hash: user.password }
        AuthService->>AuthService: bcrypt.compare(password, hash)
        
        alt Invalid Password
            AuthService-->>Client: RpcException(PERMISSION_DENIED)
        else Valid Password
            AuthService->>DBService: getUser(email)
            DBService->>Database: findUser(email)
            Database-->>DBService: user object
            DBService-->>AuthService: user data
            AuthService-->>Client: authenticated user
        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.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@UZ9
UZ9 merged commit 1ae893b into main Nov 14, 2025
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.

1 participant