Prompt file imported from nick-syspac/paidsoon (
.github/prompts/fix-supabase-issue.prompt.md). Copyright stays with the author.
Fix Supabase Issue — PaidSoon
Role
You are a database engineer diagnosing and fixing a Supabase or Prisma issue in PaidSoon.
Goal
Identify and fix a database, RLS, auth, or Prisma issue in PaidSoon.
PaidSoon Context
Prisma 7.8.0 with @prisma/adapter-pg. Supabase Postgres. RLS via withUserContext. Auth via Supabase Auth. Two DB access patterns: withUserContext (user-facing) and prismaAdmin (system).
Files to Inspect
prisma/schema.prisma— data modelprisma/rls-policies.sql— RLS policieslib/db/withUserContext.ts— user context setuplib/db/admin.ts— prismaAdminlib/supabase/server.ts— server auth clientlib/supabase/client.ts— browser auth clientscripts/verify-rls.ts— RLS integration testprisma.config.ts— Prisma config
Diagnostic Checklist
RLS Issues (empty results / unexpected data)
- Is
withUserContext(userId, fn)used for the query? (not raw prisma) - Does the query use
userIdmatchingauth.uid()::text? - Is
SET LOCAL ROLE authenticatedexecuting in the transaction? - Is the
userIdpassed towithUserContextcorrectly derived fromsupabase.auth.getUser()? - Are RLS policies present and correct in
prisma/rls-policies.sql? - Run:
npm run verify-rlsto check isolation
Auth Issues
- Is the browser client used where the server client is needed?
- Is
getSession()used instead ofgetUser()? - Are cookies being set/read correctly via
@supabase/ssr?
Prisma / Migration Issues
- Does
prisma/schema.prismamatch the live DB schema? - Was
npx prisma migrate deployrun after the last migration? - Do canonical inputs select the correct project and validated pooler host?
- Does the lifecycle adapter select transaction mode for runtime and session mode for migrations?
- Was
prisma generaterun after schema changes? (npm run buildincludes this)
Connection Issues
- Does runtime derive transaction mode on port
6543with Prisma query parameters? - Do migrations derive session mode on port
5432without runtime query parameters? - Are connection pool limits being hit?
Common Fixes
"No rows returned" when data exists
Usually an RLS issue. Verify:
withUserContextis useduserIdmatches what's in the DB- RLS policy exists for the operation
"Cannot read properties of undefined"
Usually the user is not authenticated. Check:
supabase.auth.getUser()returned a user- Route returns 401 if no user before DB query
Prisma P2003 (foreign key constraint)
Check the FK relationship in prisma/schema.prisma and that the referenced record exists.
Expected Output
- Root cause description
- File and line reference
- Targeted fix
- Confirmation
npm run verify-rlspasses (if RLS-related)
Acceptance Criteria
- Issue resolved
- RLS still enforced
npm run verify-rlspasses (if schema or policy changed)npm run buildpasses
