5.0 KiB
5.0 KiB
Session Handoff: Edge Functions, Auth Pattern, and Test Fixes
Date: 2026-04-20 Session Duration: ~2 hours Session Focus: Fix create-reservation Edge Function auth, resolve 12 failing integration tests, fix RBAC RLS, add SELinux dev docs Context Usage at Handoff: ~60%
What Was Accomplished
- Diagnosed and fixed SELinux blocking Edge Functions locally → documented fix in
CLAUDE.md - Updated Edge Function auth from
userClient.auth.getUser()(anon key + auth header) toadminClient.auth.getUser(token)(service role + JWT arg) →supabase/functions/create-reservation/index.ts - Fixed
weekSlot()test helper returning{start, end}instead of{start_time, end_time}→tests/integration/booking-constraints.test.ts - Fixed overlap tests using days 30/31/32 (same ISO week, hitting weekly pre-booking limit before DB overlap constraint fires) → spread across days 14/21/28 (different weeks)
- Fixed RBAC:
"Authenticated users can read non-private reservation slots"policy onreservationswas never dropped whenreservation_slotsview was created → new migration drops it - Fixed
reservation_slotsview fromsecurity_invoker = truetosecurity_invoker = falseso it reads as owner, not caller → new migration recreates view + grants - Fixed E2E test asserting
"Welcome to OYS Borrow a Boat"(doesn't exist) → changed to"Upcoming Reservations"which is always present when authenticated - Added
v-if="authStore.user"toIonMenuinapp.vue— menu not rendered before login - Added
yarn test:allscript (unit → integration → e2e in sequence)
Decisions Made This Session
- Use
adminClient.auth.getUser(token)(notgetClaims) BECAUSEgetClaimsis not reliably available innpm:@supabase/supabase-js@2Deno import and its return shape is undocumented for that context — STATUS: confirmed reservation_slotsview usessecurity_invoker = falseBECAUSEsecurity_invoker = truecaused it to apply the calling user's RLS (returning 0 rows for non-owners after broad policy was dropped) — STATUS: confirmed- Overlap tests use weeks 14/21/28 days ahead BECAUSE original days 30/31/32 fell in the same ISO week; direct insert on day+31 consumed the 2nd weekly pre-booking slot, blocking the day+32 "different time" test — STATUS: confirmed
Key Numbers Generated or Discovered This Session
- Integration tests before: 12 failed / 8 passed (20 total)
- Integration tests after: 0 failed / 20 passed (ASSUMED — verify with
yarn test:integration) - E2E tests: 1 failed / 1 passed → 2 passed after auth text fix (ASSUMED — verify with
yarn test:e2e)
Files Created or Modified
| File Path | Action | Description |
|---|---|---|
supabase/functions/create-reservation/index.ts |
Modified | Auth: getClaims → adminClient.auth.getUser(token); claims.sub → user.id |
tests/integration/booking-constraints.test.ts |
Modified | weekSlot key names fixed; overlap test days spread across weeks |
tests/e2e/auth.spec.ts |
Modified | Assertion changed from missing text to "Upcoming Reservations" |
app/app.vue |
Modified | v-if="authStore.user" on IonMenu |
package.json |
Modified | Added test:all script |
CLAUDE.md |
Modified | Added Edge Functions section: SELinux fix, auth pattern, security_invoker note |
supabase/migrations/20260420180000_drop_open_reservations_read_policy.sql |
Created | Drops "Authenticated users can read non-private reservation slots" policy |
supabase/migrations/20260420190000_fix_reservation_slots_view.sql |
Created | Recreates reservation_slots with security_invoker = false; grants SELECT to authenticated |
supabase/migrations/20260420132336_booking_rules_and_rbac.sql |
Modified | Fixed original view creation to security_invoker = false + added GRANT for db reset consistency |
What the NEXT Session Should Do
- First: Verify all tests pass —
yarn test:all(requires local Supabase running with functions served) - Then: Work on reservations UI —
app/pages/reservations/exists but contents unknown; likely needs create/list/detail pages wired to the Edge Function
Open Questions Requiring User Input
- What pages exist under
app/pages/reservations/? Are they scaffolded or complete? — impacts next UI session scope - Are there additional Edge Functions planned (e.g., cancel-reservation, admin endpoints)? — impacts function auth pattern reuse
Assumptions That Need Validation
- ASSUMED:
yarn test:allpasses cleanly after migrations applied — validate by runningnpx supabase migration up && yarn test:all - ASSUMED:
reservation_slotsview grant is sufficient for anon client queries in tests — validate by observing RBAC test pass
Files to Load Next Session
docs/summaries/handoff-2026-04-20-edge-functions-auth-and-test-fixes.md— this filesupabase/functions/create-reservation/index.ts— if continuing Edge Function workapp/pages/reservations/— if working on reservations UI