Skip to content

fix: standardize user id field to req.user.sub across routes - #10

Open
Ashusf90 wants to merge 1 commit into
Aman-Cool:mainfrom
Ashusf90:patch-2
Open

Ashusf90 wants to merge 1 commit into
Aman-Cool:mainfrom
Ashusf90:patch-2

Conversation

@Ashusf90

Copy link
Copy Markdown

Description

This PR resolves inconsistency in how user IDs are accessed across different routes.

Changes Made

  • Replaced all usages of req.user.id with req.user.sub
  • Ensured consistent use of JWT standard claim (sub) across:
    • users routes
    • symptoms routes
    • posts routes
    • bookings routes

Why This Change

  • sub is the standard JWT claim for user identity
  • Prevents potential bugs if id is not mapped in middleware
  • Improves consistency and maintainability

Closes #7

@Aman-Cool Aman-Cool left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

hey @Ashusf90; Thanks for picking this up! The direction is right but there are two problems that need fixing before this can merge.


Bug - typo introduces a regression

In posts.js, the like-toggle route has a typo:

// line ~63 — POST /:id/like
const userId = req.user.aub;   // ← should be req.user.sub

req.user.aub is undefined, so:

  • (p.likes || []).includes(undefined) always returns false — the liked flag is always wrong
  • The likes array gets undefined pushed into it and written back to the DB, corrupting stored data

Incomplete - symptoms.js and bookings.js not updated

The issue listed four files with the inconsistency. This PR only touches posts.js. The following files still use req.user.id and need the same change:

  • server/src/routes/symptoms.js
  • server/src/routes/bookings.js

(users.js already used req.user.sub so that one is fine.)


Once those two things are fixed this looks good to merge. Happy to re-review quickly.

Aman-Cool

This comment was marked as duplicate.

@Aman-Cool
Aman-Cool self-requested a review May 25, 2026 13:14
@Aman-Cool

Copy link
Copy Markdown
Owner

@Ashusf90, any updates?

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.

req.user.id vs req.user.sub inconsistency across routes

2 participants