Skip to content

fix(getUserFollowInfo): replace isUndefined with null-safe check for missing user#324

Open
Anton-dev3306 wants to merge 1 commit into
QuoteVote:mainfrom
Anton-dev3306:fix/get-user-follow-info-null-check
Open

fix(getUserFollowInfo): replace isUndefined with null-safe check for missing user#324
Anton-dev3306 wants to merge 1 commit into
QuoteVote:mainfrom
Anton-dev3306:fix/get-user-follow-info-null-check

Conversation

@Anton-dev3306
Copy link
Copy Markdown
Contributor

Description

This PR fixes a bug in getUserFollowInfo.js where the existence check for a user was using isUndefined(userData) from lodash. UserModel.findOne() returns null when no document is found, not undefined. Since isUndefined(null) evaluates to false, the guard never triggered, causing the function to attempt accessing userData._followingId on a null object and throwing:

TypeError: Cannot read properties of null (reading '_followingId')

Changes

  • Replaced isUndefined(userData) with !userData: Correctly handles both null and undefined return values from Mongoose.
  • Removed unused isUndefined import from lodash: The import is no longer needed after the fix.

Verification

  • Confirmed that calling getUserFollowInfo with a non-existent username now returns { error: true, message: 'No user found' } instead of throwing a TypeError.

Related Issue

Fixes #323

@netlify
Copy link
Copy Markdown

netlify Bot commented May 3, 2026

Deploy Preview for quotevote canceled.

Name Link
🔨 Latest commit 81c5908
🔍 Latest deploy log https://app.netlify.com/projects/quotevote/deploys/69f6b1d89cb8fd0008a3adbe

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.

getUserFollowInfo crashes with TypeError when username does not exist — incorrect null check

1 participant