fix: singleton Supabase admin client in requireAuth middleware
From the PR description
Summary
- Extracts a module-level
_adminClientsingleton fromrequireAuth- the client is lazy-initialised on first use and reused across all requests - The service-role client is stateless (
persistSession: false), so sharing it is safe - Removes stray
editResolutionLogging.test.tsthat was copied from an unrelated branch and caused test failures on this branch
Closes #103 Closes #115 Closes #116 Closes #125
Changes
backend/src/middleware/auth.ts- singleton admin client viagetAdminClient()backend/src/middleware/__tests__/auth.test.ts- tests for 401 (missing header), 500 (missing env vars), and success pathbackend/vitest.config.ts-isolate: trueadded for consistent module isolationbackend/package.json-"test": "vitest run"script added
Test plan
- Unit tests added and passing (3/3)
- Backend build passes
Our analysis
Singleton admin client in requireAuth middleware — read the full analysis →
Think the analysis missed something the PR description covers?
Capture this PR into my fork
Download a Markdown prompt that tells Claude how to port every
commit in this PR into your working tree. Run it via
claude -p < capture-pull-109.md from
inside the repo you want the changes in.