Commit 6719eb8
committed
fix(pairing): console proxy calls service directly + don't log out on downstream 401
Two stacked bugs the user hit on the QR-pair page:
1. Backend — the console proxy at /api/console/proof-pairing/* forwarded
to /v1/proof-pairing/* over loopback HTTP using x-zeroauth-tenant-*
headers that the /v1 layer never actually trusts. The /v1 layer
ran authenticateTenantApiKey() like every other v1 route, found
no Authorization: Bearer za_live_* header, and returned 401
missing_api_key. The dashboard surfaced it as 'Something went
sideways'.
Fix: drop the HTTP roundtrip. Same Node process; just call the
service functions in src/services/proof-pairing.ts directly. The
console JWT already authenticated the tenant — we have the
tenantId in hand. Mint the session_bind cookie at
Path=/api/console/proof-pairing/ so the browser ships it back
on subsequent same-origin reads, identical UX, no upstream API
key needed.
createSession()'s apiKeyId is now nullable; null means the call
came via the console JWT path (audit row records
actorType='console' instead of api_key).
Dropped helpers no longer referenced: PAIRING_UPSTREAM_BASE,
PAIRING_INTERNAL_HEADER, rewriteSetCookiePath, FetchResponse,
PairingProxyResult, pairingFetch, applyPairingCookies, pipeJson,
buildPairingError, handleUpstreamFailure. ~250 lines deleted,
~150 lines added.
2. Frontend — dashboard/src/lib/api.ts cleared the console token on
ANY 401 from /api/console/*, even when the 401 was a downstream
symptom (like the missing_api_key cascade above). Clicking
'Start over' on the QR-pair error card retried createSession,
got 401, wiped the token, next render = signed-out. Narrowed
the token-purge to JWT-specific machine codes ('unauthorized'
and 'session_expired') so a stale tenant config doesn't kick
the user out of the whole console.
Test sweep: 276/276 backend (jest), 31/31 dashboard (vitest).1 parent 0224be4 commit 6719eb8
3 files changed
Lines changed: 158 additions & 255 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
115 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
116 | 133 | | |
117 | 134 | | |
118 | 135 | | |
| |||
0 commit comments