2.6 KiB
2.6 KiB
plan, phase, title, status, completed
| plan | phase | title | status | completed |
|---|---|---|---|---|
| 36-01 | 36 | isAdmin schema, requireAdmin middleware, /api/auth/me surface, grant script | complete | 2026-04-19 |
What Was Built
Server-side admin foundation for Phase 36:
- isAdmin column added to the
userspgTable insrc/db/schema.ts—boolean("is_admin").notNull().default(false). - Drizzle migration generated (
drizzle-pg/0009_spotty_lord_tyger.sql) withALTER TABLE "users" ADD COLUMN "is_admin" boolean DEFAULT false NOT NULL. DB push could not be applied (DB not reachable with default credentials — requiresDATABASE_URLenv var pointing to the running Postgres instance). - requireAdmin middleware added to
src/server/middleware/auth.ts— readsuserIdfrom context (set byrequireAuth), queriesusers.isAdmin, returns 401 if userId missing, 403 if!user.isAdmin, callsnext()for admins. - isAdmin in /api/auth/me —
src/server/routes/auth.tsnow includesisAdmin: fullUser?.isAdmin ?? falsein the returned user object. /api/admin/placeholder route —src/server/routes/admin.tsappliesrequireAuth+requireAdminmiddleware on/*and returns{ ok: true }onGET /.- Route registration —
src/server/index.tsimports and registersapp.route("/api/admin", adminRoutes). - grant-admin script —
scripts/grant-admin.tsgrants or revokesisAdminbylogto_sub. Accepts--revokeflag. Exits 1 on missing sub or user not found.
Key Files
src/db/schema.ts— isAdmin column added to users tabledrizzle-pg/0009_spotty_lord_tyger.sql— migration filesrc/server/middleware/auth.ts— requireAdmin exportedsrc/server/routes/auth.ts— isAdmin in /me responsesrc/server/routes/admin.ts— new placeholder admin routesrc/server/index.ts— adminRoutes registeredscripts/grant-admin.ts— admin grant/revoke script
Deviations
- DB push could not be applied — the default PostgreSQL credentials (
gearbox:gearbox@localhost:5432/gearbox) don't match the running instance. The migration file is generated and correct. Apply manually with the correctDATABASE_URL:This is a deployment/environment concern, not a code defect.DATABASE_URL=<connection-string> bun run db:push
Self-Check: PASSED
- isAdmin column in schema.ts
- Migration file generated with correct SQL
- requireAdmin middleware exported from auth.ts
- isAdmin in /api/auth/me response
- /api/admin route protected by requireAuth + requireAdmin
- grant-admin.ts script created
- bun run build exits 0