Fix production mock-data gaps: wallet prefetch isolation, overview/API-key types, mock gating - #744
Merged
Jambox11 merged 1 commit intoAug 30, 2026
Conversation
…view/API-key types, and mock fallback gating - src/lib/walletsPrefetchCache.ts: prefetch now attaches the caller's session bearer token and keys its in-memory cache entry by that token, so a wallets prefetch started under one session can never be served to a different session that signs in afterward on the same tab/device within the TTL window (mux-labs#705). - src/types/overview.ts, src/types/apiKey.ts: extracted OverviewData / ApiKey / CreatedApiKey out of src/mock-data/* into canonical type modules; DashboardOverview, ApiKeysTable, APIKeyModal, and the useApiKeys/useRevokeApiKey hooks now type against these instead of the mock fixtures, so a real mux-backend response only needs to satisfy the real contract (mux-labs#706, mux-labs#707, mux-labs#708). - src/app/api/overview/route.ts and src/app/api/api-keys/route.ts (GET/POST/PATCH): gated the mock-data fallback behind isMockFallbackAllowed(), matching /api/wallets and /api/activity, so a production deployment with no backend configured returns 503 instead of silently listing/creating/revoking against mock data (mux-labs#706, mux-labs#707). - src/components/APIKeyModal.tsx: the modal's standalone (no onCreateKey) key generator now throws instead of fabricating a secret when isMockFallbackAllowed() is false (mux-labs#708). - Updated README.md, docs/frontend-env-vars.md, and src/docs/API_Hooks.md to describe the new production/mock split and type ownership. Closes mux-labs#705, Closes mux-labs#706, Closes mux-labs#707, Closes mux-labs#708 WARNING: implementation only, per explicit instruction — no automated test coverage (Vitest/Playwright) was added for these changes, despite the linked issues' acceptance criteria asking for it. Please add regression tests before/while merging.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/lib/walletsPrefetchCache.tsnow attaches the caller's session bearer token to the prefetch request and keys the in-memory cache entry by that token, so a wallets prefetch started under one session can never be served to a different session that signs in afterward on the same tab/device within the 30s TTL. Previously the prefetch sent no auth header at all and the cache was a single unkeyed module-level entry.OverviewData(src/types/overview.ts) andApiKey/CreatedApiKey(src/types/apiKey.ts) out ofsrc/mock-data/*into their own canonical type modules.DashboardOverview,ApiKeysTable,APIKeyModal, and theuseApiKeys/useRevokeApiKeyhooks now type against these instead of the mock fixtures, so a realmux-backendresponse only has to satisfy the real contract.src/mock-data/*re-exports the same types for backward compatibility.src/app/api/overview/route.ts(GET) andsrc/app/api/api-keys/route.ts(GET/POST/PATCH) behindisMockFallbackAllowed(), matching the existing/api/walletsand/api/activitypattern. A production deployment with no backend configured now returns503 backend_unavailableinstead of silently listing/creating/revoking against the mock store.APIKeyModal's standalone key generator (used only when the caller renders it without anonCreateKeyhandler, e.g. Storybook) now throws instead of fabricating a secret whenisMockFallbackAllowed()isfalse, so it can't hand out a fake key in a production deployment.README.md,docs/frontend-env-vars.md, andsrc/docs/API_Hooks.mdto describe the new production/mock split and type ownership.Closes #705
Closes #706
Closes #707
Closes #708
This PR is implementation only, per explicit instruction from the requester. No automated test coverage (Vitest or Playwright) was added, even though all four linked issues' acceptance criteria ask for tests that fail if the gap returns. Please add regression tests covering:
Authorizationheader./api/overviewand/api/api-keysreturning503in a production build with no backend configured.APIKeyModal's fallback key generator throwing (not fabricating a secret) when mock fallback isn't allowed.before or while merging this branch.
Test plan
pnpm test(Vitest)pnpm run typecheckpnpm run test:e2e(Playwright) for the wallets sidebar-hover prefetch and API keys create/revoke flowsNODE_ENV=productionwithNEXT_PUBLIC_API_URLunset →/api/overviewand/api/api-keys(GET/POST/PATCH) return503 backend_unavailable