feat(ui): visible auth-required affordance on 401#76
Merged
Conversation
Previously a 401 from /api/* bubbled into React Query error states
without a recognisable "sign in" surface, so the user saw a generic
"Could not load activity" card with no hint that the problem was
authentication. The auth.spec.ts Playwright smokes were held back
with test.fixme for this reason.
Wiring:
- `useAuthStore` (zustand) holds a single `authRequired` flag.
- QueryCache `onError` flips the flag when any React Query throws an
ApiErrorResponse with status === 401 — a global gate so individual
query callers don't each have to handle 401.
- AuthRequiredBanner reads the flag and renders a `role="alert"`
state-card with copy matching the flake-register regex ("Sign in",
"session has expired", "please sign in").
- Mounted inside <main id="main"> in Shell.tsx so it appears on every
route without per-route plumbing.
Re-enables ui/e2e/auth.spec.ts (two smokes, /`/` and `/notes`) and
asserts both the testid and the auth-copy regex. Vitest coverage for
the store + banner added.
Closes #66.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: af53672508
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Codex flagged the original auth gate as incomplete: the onError was only attached to QueryCache, so a 401 thrown by a mutation (note create/update/delete) would slip past and leave the user staring at an unhelpful transient error with no "Sign in required" affordance. Extract the 401 detector into a shared `gateUnauthorized(error)` helper and attach it to BOTH QueryCache and MutationCache. Add three Vitest cases: query-401 flips, mutation-401 flips, and a non-401 error does NOT flip. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
AuthRequiredBannerrenders a visible "Sign in required" state-card inside<main>whenever any React Query throwsApiErrorResponse { status: 401 }.QueryCacheonErrorthat flips a tinyuseAuthStore(zustand) — individual query consumers stay unchanged.test.fixmefromui/e2e/auth.spec.ts; both smokes (/and/notes) now pass and assert both the testid and the auth-copy regex.Closes #66.
Test Plan