fix: throw on missing env vars in backend createServerSupabase()#106
fix: throw on missing env vars in backend createServerSupabase()#106bmersereau wants to merge 4 commits into
Conversation
bmersereau
left a comment
There was a problem hiding this comment.
PR Review
Summary
Fixes a silent-fail bug in createServerSupabase() where missing env vars produced a broken client with empty-string credentials instead of throwing. The fix is correct, minimal, and well-tested. One pre-existing function in the same file (getUserIdFromRequest) still uses the old || "" pattern, but that function is currently dead code (no callers) and is out of scope for this PR.
Findings
- [severity:low]
getUserIdFromRequestinsupabase.ts(lines 29-30) still uses the old|| ""fallback pattern and creates a newcreateClienton every invocation — both issues this PR fixed forcreateServerSupabase. The function has no callers today, but should be cleaned up before it's wired to a route. - [severity:nit] Tests use dynamic
import()inside eachitblock withisolate: truein vitest config. This works, butvi.resetModules()in abeforeEachwould make the isolation intent explicit and guard against accidental module-cache sharing ifisolateis ever removed.
Verdict
Approve with nits
What I verified
- Tests: pass (4/4)
- vitest.config.ts has
includefilter: pass ("src/**/__tests__/**/*.test.ts") - package.json has
"test": "vitest run": pass createServerSupabasethrows on missing URL, missing key, both missing, and returns client when both set: pass
bmersereau
left a comment
There was a problem hiding this comment.
PR Review
Summary
Replaces the silent || "" fallbacks in createServerSupabase() with an explicit guard that throws when either env var is absent. Four unit tests cover all combinations of missing/present env vars. Simple, correct, well-tested change.
Findings
- [severity:praise] Error message
"SUPABASE_URL and SUPABASE_SECRET_KEY must be set"is clear and actionable - [severity:praise]
persistSession: falsealready present — service-role client correctly stateless - [severity:nit] Tests import via dynamic
await import("../supabase.js")without module reset between tests — env var deletions inbeforeEachmay not fully isolate if the module is cached. Tests still pass because vitest'sisolate: truein vitest.config.ts handles this
Specific checks
-
"test": "vitest run"in package.json ✓ -
vitest.config.tsinclude filter present ✓ - Tests pass: 4/4 ✓
- documents.ts unchanged from origin/main ✓
Verdict
Approve — clean.
bmersereau
left a comment
There was a problem hiding this comment.
Follow-up Review (pass 2)
Change
Removed dead getUserIdFromRequest export — function had no callers and still used the old || "" pattern that this PR was eliminating.
Findings
- [severity:praise] File is now clean — only
createServerSupabaseremains, with the correct guard - No regressions. Tests still pass 4/4.
Verdict
Approve — all pass-1 findings resolved.
Summary
backend/src/lib/supabase.tsnow throwsError("SUPABASE_URL and SUPABASE_SECRET_KEY must be set")when either env var is absent, matching the frontend fix from PR fix: remove auth bypass dev fallback in getUserIdFromRequest #73getUserIdFromRequestexport (no callers) which still used the old|| ""patternCloses #97
Closes #114
Closes #117
Closes #124
Changes
backend/src/lib/supabase.ts— replace|| ""fallbacks with explicit guard; remove deadgetUserIdFromRequestexportbackend/src/lib/__tests__/supabaseServer.test.ts— new test: throws on missing URL, missing key, both missing; succeeds when both setbackend/vitest.config.ts— vitest configuration withincludefilter andisolate: true;"test"script added topackage.jsonTest plan