refactor(auth): collapse lib/auth-context.js + lib/admin-auth.js onto lib/use-auth.js #31
No reviewers
Labels
No labels
agent-context-drift
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: rstillwell/deckhearth#31
Loading…
Reference in a new issue
No description provided.
Delete branch "convoy/single-auth-provider"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
P1 quality (launch sequence step 9 —
.convoys/ship-readiness.md§ P1 entry 9). Collapses thethree parallel client-side auth implementations onto
lib/use-auth.jsas the canonicalsingle surface. Pre-convoy, a worst-case page mount issued 3 identical
GET /api/auth/verifyroundtrips (one per provider/hook). Post-convoy: 1 verify per page mount.
The other two surfaces (
lib/auth-context.jsandlib/admin-auth.js) are deleted; everyimporter is migrated; the
<AuthProvider>wrapper is removed frompages/_app.js. No testschange. Convoy file: .convoys/single-auth-provider.md.
Decisions (full text in convoy file)
lib/use-auth.js. Zero call sites readlogin()/register()fromuseAuth(); those flows live inpages/login.js/pages/signup.jswhichhit
/api/auth/{login,register}directly and write the token tolocalStorage. Preservingthe legacy methods would have been cargo-culting.
useIsAdmin()migration.pages/card/[id].jsis the only consumer. Replaced withconst isAdmin = user?.role === 'admin'derived from the existinguseAuth()call. Rendercondition byte-identical.
_app.jsprovider tree.<ThemeProvider><AuthProvider>{children}</AuthProvider></ThemeProvider>→
<ThemeProvider>{children}</ThemeProvider>.useAuthis hook-only; no replacementProvider needed.
card/[id].js; 2 → 1 on every other page-load.server-side (auth-secret / permission-middleware / auth-utils — 16 tests) or prop-driven
(
Layout.test.js— 5 tests; passesuseras a prop, never imports a hook).Importer inventory
lib/auth-context.js→lib/use-auth.js(6 source files)pages/_app.jsAuthProviderpages/index.jsuseAuthpages/scanner.jsuseAuthpages/decks.jsuseAuthpages/deck/[id].jsuseAuthpages/deck-builder.jsuseAuthlib/admin-auth.js→ consolidated ontouseAuth(1 source file)pages/card/[id].jsuseIsAdminuser?.role === 'admin'from existinguseAuth()(D2)AdminProvideranduseAdmin()had zero importers — confirmed dead exports.Adjacent doc / config sweeps
.github/CODEOWNERS— dropped 2 lines for deleted files.AGENTS.md§ 2 + § 3 — architecture row + "Auth (client)" convention rewritten..cursor/rules/auth-and-permissions.mdc— § Legacy reframed as "deleted by this convoy"; §"Authentication state on the client" updated to post-convoy shape + direct-fetch login flow.
.cursor/rules/no-go-zones.mdc— auth-refactors bullet drops deleted files..cursor/skills/add-page/SKILL.md— checklist + anti-pattern row updated.Provider tree (before / after)
<AdminProvider>was never wired in_app.jsto begin with (verified pre-convoy), so noremoval needed there.
Verification
rg "lib/auth-context|lib/admin-auth" --type js→ 0 hits inpages/,lib/,components/.npm run lint→ 128 → 125 problems (3 fewer errors, from deleted unused-importlines; no regression).
npm run test:run→ 21/21 pass, including the 5 Layout regression locks fromfix-layout-default-user(prop-driven, unaffected).npm run build→ succeeds end-to-end; all 26 pages compile (10 dynamic API routes + 16pages/**views including every file modified). No SSR / static-generation breakagethat would have surfaced if a page tried to use the legacy context hook unwrapped.
npm run dev, log in, click arounddashboard / profile / settings / collections / cards /
card/[id]/ admin/card-editor;verify the orange "Edit Card" admin button on
card/[id]still appears for an adminuser — that's the only
useIsAdminconsumer behaviour). Documented in convoy file §Verification step 5.
Risks (full discussion in convoy file)
<AuthProvider>.useEffect-guardedlocalStorageread in
useAuthkeeps SSR shape identical pre/post; build passes.refreshAuth()preserved on the canonical hook for that purpose; no consumer needs ittoday.
useAuthcache across components. Pre-existing pattern, called out as afollow-up rather than addressed here.
Conflict-with-parallel-PR awareness
Parallel
single-sql-clientconvoy may also touch somepages/**files. Conflicts possibleat the import block of any page that uses both legacy auth and legacy SQL clients; merge-time
rebase will handle.
Follow-ups
useAuthcache audit (the original motivation for the legacy context — athin re-introduction may be the right answer if shared state across components on the same
page becomes a measured cost).
lib/use-auth.js::checkAuth.getServerSideProps) to eliminate thepage-mount verify roundtrip entirely. Larger architectural conversation.
.convoys/ship-readiness.md§ P1 → entry 9 RESOLVEDwith squash SHA.
Made with Cursor
The latest updates on your projects. Learn more about Vercel for GitHub.
Pipeline Health
Build + CI gates
Build runs on Vercel; this CI runs lint and schema-map drift only (no duplicate build).
Role reports
See individual comments above for details. This rollup updates automatically.
Visual Diff
Screenshots and diffs uploaded as artifacts: view run
If intentional changes: update snapshots locally with
npx playwright test --project=visual --update-snapshotsand commit.