fix(#712/#711/#710/#709): wire auth tokens, mock IDs, limits API, set… - #747
Merged
Merged
Conversation
…okens, mock IDs, limits API, settings backend mux-labs#712 — login route now echoes a session block in its JSON response when the backend returns a token, so the client can persist it to sessionStorage and attach Authorization: Bearer on wallet/API requests. Previously only the HttpOnly cookie was set server-side; client fetches went out unauthenticated. mux-labs#711 — export MOCK_WALLET_IDS constants from src/mock-data/wallets.ts. WalletDetail.stories.tsx now references those constants instead of hardcoded strings, so a mock ID rename propagates from one place and stories never silently load a NotFound state. mux-labs#710 — SpendingLimitsCard now passes Authorization: Bearer on every fetch to /api/spending-limits. The route itself now requires a Bearer token (401 otherwise) and has an explicit isMockFallbackAllowed() guard: default limits are returned in dev/CI, 503 backend_unavailable in production with no backend. mux-labs#709 — new /api/settings route (GET + PATCH) proxies to MUX_BACKEND_URL/developers/me/settings, requires Bearer auth, returns a mock echo in dev and 503 in production with no backend. Settings page is rewritten to load from and save to /api/settings instead of localStorage; no project preferences ever touch the browser store.
|
@yahia008 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Title: fix: wire auth tokens, mock IDs, limits API, and settings backend
(#712/#711/#710/#709)
──────────────────────────────────────────────────────────────────────────────────
Description:
Closes #712
Closes #711
Closes #710
Closes #709
Summary
Four related gaps that caused the dashboard to serve mock data, unauthenticated
requests, and local-only state in production.
──────────────────────────────────────────────────────────────────────────────────
#712 — Login must store tokens required by wallet routes
POST /api/auth/login only wrote the backend's session token to the HttpOnly cookie
— no token block was returned to the client. useWallets and other client fetches
rely on Authorization: Bearer from sessionStorage, so they were hitting
the wallets route unauthenticated and getting 401s.
Fix: when the backend returns a token, the login route now synthesises a session
block in the JSON response alongside the HttpOnly cookie. AuthContext.signIn
already persisted it to sessionStorage; now it has something to persist.
──────────────────────────────────────────────────────────────────────────────────
#711 — Wallet detail page must not depend on Storybook mock IDs
Stories used hardcoded ID strings ("wallet-001", etc.) that had to stay in sync
with src/mock-data/wallets.ts by convention.
Fix: MOCK_WALLET_IDS constants exported from src/mock-data/wallets.ts.
WalletDetail.stories.tsx now imports them — a rename or addition propagates from
one place. Tests verify every constant resolves to a real dummyWallets entry with
the correct network/status.
──────────────────────────────────────────────────────────────────────────────────
#710 — Spending limits must use Limits API, not local store
SpendingLimitsCard called fetch("/api/spending-limits") without an Authorization
header. The route also had no auth gate and no explicit production/mock split.
Fix: SpendingLimitsCard now reads the bearer token from sessionStorage and
attaches it on all GET and PUT requests. The route requires a Bearer token (401
otherwise), returns mock defaults in dev/CI, and returns 503 backend_unavailable
in production with no backend.
──────────────────────────────────────────────────────────────────────────────────
#709 — Settings page must persist to backend
The settings page read and wrote preferences from localStorage — changes were
browser-local, not persisted to any account, and silently lost if localStorage was
cleared.
Fix: new GET/PATCH /api/settings route proxies to
MUX_BACKEND_URL/developers/me/settings, requires Bearer auth, echoes a mock
payload in dev, and returns 503 in production with no backend. Settings page is
rewritten to load on mount and save on submit via the API; localStorage is no
longer touched.
──────────────────────────────────────────────────────────────────────────────────
Tests
real-backend paths
matching dummyWallets entry
and proxy behavior (preserves original coverage)
production 503, and proxy for both GET and PATCH
Authorization header sent, no localStorage writes
verifying Authorization header is sent; existing assertions updated to
objectContaining
Production/mock split
All four routes follow the same pattern as the rest of the app: mock fallback
allowed outside production, explicit 503 backend_unavailable in production with no
backend configured. No new default secrets. No credentials in NEXT_PUBLIC_* or
localStorage.