Claude Code Build Night · Part 11 · Coming soon

Admin Console

Build the internal tool that runs the business.

How the night runs.

Twenty minutes of AI news, then we build the admin console for What's for Dinner from one ADMIN.md, then five-minute demos from the room.

  1. 01

    Roles

    Better Auth's admin plugin and the first admin.

  2. 02

    Pages

    Metrics, users, support, dinners and the audit log.

  3. 03

    Actions

    Ban, hide, reset, impersonate, each confirmed.

  4. 04

    Audit

    Every action logged, every route checked.

The deck.

Every slide from the night, free to share. Open it full size to step through.

Admin Console · slidesOpen full size →

Tonight's console.

The internal tool that runs the app, written down before it's built. Paste it into your repo and let Claude Code build from it.

ADMIN.mdWhat's for Dinner

What's for Dinner

Two roles, five pages, seven actions and an audit log, all inside the same Next.js app and locked on the server.

The ruleThe server decides, and every action leaves a record.

  • Better Auth admin plugin
  • shadcn/ui
  • TanStack Table
  • Neon
  • AI SDK
  • AI Gateway
  • Playwright
Done when
  • A normal user gets nothing from /admin, proven by a test
  • Find a user, see their dinners, ban them with a reason
  • Hide a bad recipe and the user stops seeing it
  • Every action shows up in the audit log
  • Impersonation shows a banner and is logged
The full ADMIN.md
# What's for Dinner - ADMIN.md

The internal tool that runs What's for Dinner. It lives at /admin inside the same Next.js app, uses the same Better Auth sessions and the same Neon database, and only admins can reach it.

## Rules
- Least privilege: two roles to start. Nobody gets admin who doesn't need it.
- The server decides. Every /admin page, server action and route handler checks the role on the server. Hiding a link is not a check.
- Every admin action writes one row to the audit log, in the same request as the action. No audit row, no action.
- No secrets in the browser. Database URLs, AI keys and auth secrets stay in server code and .env.local.
- Row level security is forced on user tables (SECURITY.md), so admin reads go through the server-only connection in lib/db-privileged.ts, and only after requireAdmin().
- Destructive actions (ban, hide, revoke sessions, impersonate) ask for confirmation and a reason.
- Impersonation is logged when it starts and when it stops, and the app shows a banner while it's on.

## Roles
Better Auth's admin plugin, with its default roles:
- `admin`: full access to /admin
- `user`: the app only, no access to /admin (the default for new sign-ups)

The first admin is created from the terminal by the founder, never from the app.

## Pages
1. /admin - metrics: signups, activated users, weekly active
2. /admin/users - users table: search by email or name, filter by role or banned, sort by created date
3. /admin/users/[id] - support view: profile, recent dinners, sessions, actions, AI summary
4. /admin/dinners - dinners: newest first, open one, hide a bad recipe with a reason
5. /admin/audit - audit log: newest first, filter by admin, action or target

## Actions
| Action | Who | Confirm | Audit event |
|---|---|---|---|
| Set role | admin | yes | user.set_role |
| Ban / unban | admin | yes, with reason | user.ban / user.unban |
| Revoke sessions | admin | yes | user.revoke_sessions |
| Send password reset | admin | yes | user.password_reset_sent |
| Impersonate / stop | admin | yes, with reason | user.impersonate_start / user.impersonate_stop |
| Hide / unhide recipe | admin | yes, with reason | recipe.hide / recipe.unhide |
| AI summary | admin | no | ai.summarize_user |

## Audit log
Table `admin_audit_log`: id, actor_id, action, target_type, target_id, reason, metadata (JSON), created_at. Insert and read only. Nothing in the code updates or deletes a row.

## Metrics
- Signups: new users per week
- Activated: new users whose first three dinners were found within 24 hours of signup (first `dinners_found`)
- Weekly active: users who found dinners at least once that week
These match GROWTH.md from Part 7. If GROWTH.md changes, it wins.

## Done when
- [ ] Signed out, or signed in as a normal user, /admin and every admin action return no data (a Playwright test proves it)
- [ ] An admin can find a user by email, see their recent dinners and ban them, with a confirmation
- [ ] An admin can hide a bad recipe, and the user no longer sees it, in dinners or Favorites
- [ ] Every action above shows up in /admin/audit with who, what, when and why
- [ ] Impersonation shows a banner and writes a start and a stop row

The prompts.

Every prompt from the deck, in order. Open one, copy it, paste it into Claude Code, Codex or any coding agent.

  1. 01
    Write ADMIN.md first
    Read SPEC.md and look at the current database schema and auth setup. We're adding an internal admin console at /admin inside this same Next.js app.
    
    Interview me one question at a time and wait for each answer:
    - Which jobs do I do for users today, by hand or in the database?
    - Which of those are destructive and need a confirmation and a reason?
    - Who needs admin access, and who doesn't?
    - Which three numbers I want to see every morning (use GROWTH.md if it exists)
    
    Then write ADMIN.md with these sections: Rules, Roles, Pages, Actions (a table with who, confirm and audit event), Audit log, Metrics, Done when.
    
    The Rules section must say: least privilege; every page and action checks the role on the server; every admin action writes an audit row; no secrets in the browser; destructive actions confirm; impersonation is logged.
    
    Stop and wait for my OK before writing any code.
  2. 02
    Roles with Better Auth's admin plugin
    Read ADMIN.md. Add roles with Better Auth's admin plugin. Check the current docs at better-auth.com/docs/plugins/admin before writing code. Stop after each step.
    
    1. Add admin() from better-auth/plugins to the server auth config and adminClient() from better-auth/client/plugins to the auth client. Keep the default roles: admin and user, with user as the default for new sign-ups.
    2. Add the plugin's database columns the way Better Auth's docs say for this project's setup (npx auth@latest migrate or generate). Show me what changes before applying it.
    3. Tell me to create the first admin myself in my terminal with:
       npx auth@latest create-admin --email <my email> --name "<my name>" --role admin
       Wait until I tell you it's done.
    
    Don't build any admin pages yet. Never put my password or any secret in a file or in chat.
  3. 03
    Lock the door on the server
    Read ADMIN.md. Lock /admin down on the server before building any page. Stop after each step.
    
    1. Write one server-only helper, requireAdmin(), that reads the Better Auth session from the request headers and returns the user only if their role is admin. Otherwise it stops the request (notFound or a 403) before any data is loaded. Part 9 forced row level security on dinners, favorites and plans, so every admin data path runs after requireAdmin() through lib/db-privileged.ts, the server-only connection from Part 9, never lib/db-as-user.ts. If that file doesn't exist yet, read SECURITY.md, section Data, and ask me before creating it.
    2. Call it in app/admin/layout.tsx, and also at the top of every admin page, server action and route handler. Don't rely on the layout alone, and don't rely on hiding links.
    3. Check for playwright.config.ts (Part 4 created it). If it exists, reuse it. If it doesn't, tell me to run npm init playwright@latest myself and wait until I tell you it's done.
    4. Write e2e/admin-access.spec.ts with three tests: signed out, /admin shows no admin content; signed in as a normal test user, /admin and one admin server action return no data; signed in as an admin, /admin loads. Read test account emails and passwords from environment variables I'll add to .env.local myself; never write real credentials into the test.
    5. Run npx playwright test and show me the result.
  4. 04
    A users table you can search
    Read ADMIN.md. Build the audit log first, then the users table. Stop after each step.
    
    1. Create the admin_audit_log table from ADMIN.md (id, actor_id, action, target_type, target_id, reason, metadata JSON, created_at). Write one server-only function, logAdminAction(), that inserts a row. Nothing in the code may update or delete audit rows.
    2. Check for components.json. If it doesn't exist, tell me to run npx shadcn@latest init in my own terminal, because it asks questions, and wait until I tell you it's done. Then add the components this console uses: npx shadcn@latest add table button dropdown-menu input dialog textarea, and npm install @tanstack/react-table. Follow the data table guide on ui.shadcn.com.
    3. Build /admin/users. Load users on the server with Better Auth's listUsers, passing the request headers, and use its search (email or name), filter (role, banned) and sort (created date) options, with pagination.
    4. Add a row actions menu: set role, ban, unban. Each one is a server action that calls requireAdmin(), asks for confirmation in a dialog (ban also asks for a reason), calls the admin plugin, then calls logAdminAction(). An admin can't ban or demote themselves.
    5. Show me the page at desktop width and one audit row after a test ban.
  5. 05
    Hide a bad recipe
    Read ADMIN.md. Build /admin/dinners. Stop after each step.
    
    1. Propose the smallest schema change that lets an admin hide one recipe inside a dinner result, with who hid it, when and why. Wait for my OK, then apply it.
    2. Build the page: newest dinners first, with the user's email, the ingredients and the three recipe names. Opening one shows the full recipes.
    3. Add Hide and Unhide as server actions: requireAdmin(), a confirmation dialog with a required reason, the change, then logAdminAction() with recipe.hide or recipe.unhide.
    4. Update the user-facing app so hidden recipes no longer show anywhere: in that user's dinners and in Favorites (favorites from Part 4 point at dinner_id and recipe_index, so filter those out too). Keep the favorites rows so Unhide brings them back. Show me both sides: the admin view and the user's view, including Favorites.
  6. 06
    Support in one page
    Read ADMIN.md. Build the support view at /admin/users/[id]. Stop after each step.
    
    1. Show the user's profile (email, name, role, created date, banned and why), their 10 most recent dinners, and their active sessions. Load it all on the server after requireAdmin().
    2. Add three actions, each with a confirmation and logAdminAction():
       - Revoke sessions, with the admin plugin's revokeUserSessions
       - Send password reset, with Better Auth's requestPasswordReset. If the auth config has no sendResetPassword function yet, tell me and skip this one instead of adding an email provider.
       - Impersonate, with impersonateUser, asking for a reason
    3. While impersonating, show a banner across the app with a Stop button that calls stopImpersonating. Log user.impersonate_start and user.impersonate_stop, using the session's impersonatedBy field to know who the admin is.
    4. Show me the page, then the banner while impersonating a test user.
  7. 07
    Three numbers every morning
    Read ADMIN.md, and GROWTH.md from Part 7 if it exists. Build /admin, the metrics page.
    
    1. Write the queries on the server through lib/db-privileged.ts, after requireAdmin(): signups (new users per week), activated (new users whose first three dinners were found within 24 hours of signing up, the same definition as GROWTH.md) and weekly active (users who found dinners at least once that week). If GROWTH.md has changed since Part 7, use its current definitions and tell me.
    2. Show each number with last week's number beside it, and an eight-week table under each one. No charts library unless one is already installed.
    3. Call requireAdmin() first. No analytics keys or database URLs in client components.
    4. Show me the page, and the SQL behind each number so I can check it.
  8. 08
    One AI assist
    Read ADMIN.md. Add one AI assist to the support view: a Summarize button on /admin/users/[id].
    
    1. A server action calls requireAdmin(), loads the user's last 30 days of dinners and errors, and sends only what's needed (no email, no password hashes, no session tokens) to a Claude model through the AI SDK and Vercel AI Gateway with a "provider/model" string. Check the AI Gateway model list for the current Claude Sonnet model ID instead of guessing.
    2. Ask for four short lines: how often they use it, what they cook, anything that went wrong, and one suggested next step for support. It must not invent facts that aren't in the data.
    3. Use the existing AI_GATEWAY_API_KEY in .env.local; never send it to the browser. 15-second timeout, and a plain error message on failure.
    4. Log ai.summarize_user with logAdminAction(). Show me the summary for a test user.
  9. 09
    Ship the console
    Read ADMIN.md. Before we ship, review the admin console like an attacker would.
    
    1. List every file under app/admin and every admin server action and route handler, and confirm each one calls requireAdmin() before loading or changing data. Fix any that don't.
    2. Search client components for secrets or server-only imports (database URLs, AI keys, auth secrets). Fix anything you find.
    3. Confirm every action in the Actions table writes its audit event. Show me the audit log after one of each.
    4. Run npx playwright test and every check under Done when, and tell me which pass.
    5. Commit and push so Vercel deploys. Ask me before any step that needs my login, and give me the live /admin URL when it's done.

The toolkit.

Everything behind the console, one job each, inside the app you already run.

Bring your app. Leave with the controls.

Date to be announced. Dates go out in the Discord first.

Harbor at dusk · Phoenix, Arizona