4.8 KiB
4.8 KiB
Phase 36: Admin Role & Panel Foundation - Context
Gathered: 2026-04-19 Status: Ready for planning
## Phase BoundaryAdd an isAdmin boolean to the users table, protect the /admin route (server middleware + client guard), build a structured admin shell with sidebar navigation, and surface isAdmin to the client via /api/auth/me. Admin status is granted directly via SQL/Drizzle Studio — no CLI script needed.
Schema
- D-01: Add
isAdmin boolean NOT NULL DEFAULT falseto theuserstable via Drizzle migration. - D-02: No Logto role claims — isAdmin lives entirely in the GearBox database.
Admin Grant Mechanism
- D-03: No CLI script. Developers grant/revoke admin status via direct SQL (
UPDATE users SET is_admin = true WHERE ...) or Drizzle Studio. This is acceptable for a single-admin app.
Route Protection
- D-04: New
requireAdminmiddleware (extendsrequireAuth) — returns 403 JSON for any non-admin hitting/api/admin/*endpoints. - D-05: TanStack Router
beforeLoadguard on the/adminclient route — redirects non-admin users to home (/). Belt-and-suspenders: server 403 + client redirect.
Admin Nav Link
- D-06: Show a conditional "Admin" link for admin users in the user avatar/menu area of the top nav (not a top-level nav item). Keeps it scoped to account-level actions.
- D-07:
isAdminis surfaced to the client by adding it to the/api/auth/meresponse. No separate query needed.
Admin Panel Layout
- D-08:
/adminrenders a structured shell with a sidebar nav — not an empty placeholder. The shell has two nav items: Items and Tags (matching phases 37 and 38 respectively). Both are disabled/coming-soon in this phase. - D-09: This layout is the reusable admin frame — phases 37 and 38 replace the placeholder content areas without reworking the shell.
Claude's Discretion
- Exact visual styling of the admin shell (consistent with app's light/minimal aesthetic)
- Whether to add a dedicated
/adminserver-side route handler or reuse the SPA catch-all - How to structure the
requireAdminmiddleware relative torequireAuth(wrapping vs. separate)
<canonical_refs>
Canonical References
Downstream agents MUST read these before planning or implementing.
Auth & Middleware
src/server/middleware/auth.ts— existingrequireAuthmiddleware;requireAdminshould follow the same patternsrc/server/services/auth.service.ts—getOrCreateUserand user DB patterns
Database Schema
src/db/schema.ts—userstable definition; addisAdminheresrc/server/routes/auth.ts—/api/auth/meendpoint; addisAdminto response
Client Routing & Nav
src/client/routes/__root.tsx— root layout with top nav + user menu; add conditional Admin linksrc/client/routes/— TanStack Router file-based routes; createadmin.tsxandadmin/directory
Requirements
.planning/REQUIREMENTS.md— ROLE-01, ROLE-02, ADMN-01
</canonical_refs>
<code_context>
Existing Code Insights
Reusable Assets
requireAuthmiddleware (src/server/middleware/auth.ts):requireAdminfollows the same Context/Next signature — callrequireAuthfirst, then checkisAdminfrom the resolved user record- Existing Hono route patterns in
src/server/routes/— admin routes follow the same structure - TanStack Router file-based routing —
/adminbecomessrc/client/routes/admin.tsx(oradmin/index.tsx)
Established Patterns
- Auth middleware sets
userIdon Hono context;requireAdminreads theusersrecord to checkisAdmin /api/auth/mealready returns{ user, authenticated }— addisAdminto theuserobject- Light/airy design aesthetic — admin shell should match app visual style (white, minimal, no visual clutter)
Integration Points
src/server/index.ts: Register new/api/admin/*routes behindrequireAdminsrc/client/routes/__root.tsx: Conditional Admin link in user menu (readsisAdminfrom auth query)src/db/schema.ts+ migration:isAdmincolumn onuserstable
</code_context>
## Specific Ideas- Admin sidebar: two sections "Items" (phase 37) and "Tags" (phase 38) — both greyed out / "Coming soon" in this phase
- The admin shell is the persistent frame; phases 37/38 inject content into a
<Outlet>or equivalent
- Logto UI-based admin management — not possible without switching to Logto role claims (explicitly ruled out)
- Users section in admin sidebar — not in current roadmap, deferred to a future milestone if needed
- Formal CLI tool for admin grant — deemed unnecessary given direct SQL access
Phase: 36-admin-role-panel-foundation Context gathered: 2026-04-19