Skip to content

Use session.user.id instead of email for profile lookups - #83

Merged
shammy911 merged 2 commits into
KavinduSDfrom
copilot/sub-pr-79-yet-again
Mar 20, 2026
Merged

shammy911 merged 2 commits into
KavinduSDfrom
copilot/sub-pr-79-yet-again

Conversation

Copilot AI commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

The profile API was using session.user.email as the Prisma lookup/update key — a mutable, session-updatable field — creating a potential cross-user access vector.

Changes

  • app/api/user/profile/route.ts: Switch both GET and PATCH handlers to use session.user.id (immutable JWT primary key) for all findUnique/update calls
  • Tighten auth guard to explicitly reject requests where session.user.id is absent, preventing undefined from reaching the Prisma where clause
// Before
where: { email: session.user?.email || undefined }

// After
if (!session || !session.user?.id) return new Response("Unauthorized", { status: 401 });
// ...
where: { id: session.user.id }

⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

Co-authored-by: shammy911 <180457932+shammy911@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback from PR #79 on Kavindu sd implementation Use session.user.id instead of email for profile lookups Mar 20, 2026
Copilot AI requested a review from shammy911 March 20, 2026 06:34
@shammy911
shammy911 marked this pull request as ready for review March 20, 2026 07:02
@shammy911
shammy911 merged commit 1ffa40b into KavinduSD Mar 20, 2026
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.

2 participants