Commit 4957eaf3 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Fix permanently-blank admin panel and a real-network-call leak in tests

Two compounding bugs, both traced from live "Token expired on Library" /
"blank Admin panel" reports:

1. AuthContext never recovered from a failed token refresh. isAuthenticated
   only ever got set to true (on mount or dev auto-login); nothing set it
   back to false when apiFetch's own refresh-and-retry also failed and
   silently cleared localStorage out from under it. role stayed null
   forever in that state, and RequireRole renders nothing while role is
   null (to avoid flashing "access denied" during the real initial
   fetch) - so a stale/expired token produced a permanently blank page
   instead of a "not authenticated" message. Now a 401 from /auth/me
   (meaning the retry already failed) flips isAuthenticated back to
   false so the UI recovers on its own.

2. AuthContext captured VITE_DEV_ACCESS_TOKEN/VITE_DEV_REFRESH_TOKEN as
   module-level constants at import time, so every test file's
   vi.stubEnv() calls in beforeEach (all of them except AuthContext's
   own tests, which knew to work around this with vi.resetModules())
   were silent no-ops. With genuinely valid dev tokens now in .env, this
   started making real network calls to the live backend during `npm
   test` and made Nearby.test.tsx flaky (real role resolved to
   super_admin, so the real "Business" nav link collided with a
   soundmark's own tier badge text). Reading the env vars fresh inside
   the effect instead of as frozen constants fixes it for every test
   file at once, not just the ones edited here.

Also regenerated .env's dev tokens via the real auth issuance path
(_issue_tokens) so they're backed by an actual refresh_tokens DB row,
not just a bare unregistered JWT.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 162b63ec
Pipeline #1068 canceled with stage