Skip to content

Fix auth user profile sync - #3

Closed
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-correctness-bugs-ef84
Closed

Fix auth user profile sync#3
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-correctness-bugs-ef84

Conversation

@cursor

@cursor cursor Bot commented May 16, 2026

Copy link
Copy Markdown

Bug and impact

Successful Supabase signup/login returned valid auth tokens but did not create or repair the corresponding application users row. New or orphaned authenticated users then hit USER_NOT_FOUND on /users/me and foreign-key failures on profile/preferences/meal-log flows.

Root cause

AuthService only interacted with Supabase Auth. The Prisma users table is the parent for all user-scoped app data, but no production auth path inserted or backfilled that row.

Fix

  • Add a small syncUserRecord helper in AuthService that upserts the Prisma user row from the Supabase auth user.
  • Run the sync on signup, login, and refresh before returning auth success.
  • Preserve signup display names and backfill from Supabase metadata when repairing via login.
  • Add focused auth endpoint tests for signup creation and login repair.

Validation

  • pnpm install --frozen-lockfile
  • pnpm --filter @snacktrack/shared-types build
  • DATABASE_URL=postgresql://localhost:5432/snacktrack_test DIRECT_URL=postgresql://localhost:5432/snacktrack_test pnpm --filter @snacktrack/backend db:generate
  • pnpm --filter @snacktrack/backend test -- auth.test.ts
  • DATABASE_URL=postgresql://localhost:5432/snacktrack_test DIRECT_URL=postgresql://localhost:5432/snacktrack_test pnpm --filter @snacktrack/backend build
  • pnpm --filter @snacktrack/backend test ⚠️ one pre-existing-looking failure remains: tests/health.test.ts expects 200 for all services healthy, but the health route also checks ML service health and that test does not mock mlService.isHealthy(), so it returns 503.
Open in Web View Automation 

Co-authored-by: Vasanth Panuganti <vpanuga2@asu.edu>
@vasanthpanuganti
vasanthpanuganti deleted the cursor/critical-correctness-bugs-ef84 branch June 11, 2026 05:53
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