Phase 2: Admin console (admin.appe.at)

A desktop-first React app for organizers, guarded to the admin role.

Backend (supabase/migrations/20260823000000_admin_app.sql):
- Admin-only SELECT policies on preferences, connections, feedback
- reset_qr_token RPC: regenerates a lanyard token, re-hashes it as the
  Auth password (old token stops working), and clears the attendee's
  sessions to force re-login

App (apps/admin, port 3001):
- Login: same QR+email flow, but non-admin sessions are rejected
- Dashboard: live stats + top points + recent activity
- Attendees: search, edit name/company/role, reset QR, adjust points
- Schedule: manage slots + sessions (create/edit/delete)
- Activity: check-ins / connections / feedback tables
- Same-origin proxy (Vite dev / nginx in Docker), same design tokens

Docker + scripts:
- convivo-admin service in docker-compose.yml (:3001)
- admin:dev / admin:build root scripts
- fixed db:reset script (supabase reset -> supabase db reset)

Docs: new frontend/admin-app.md; updated architecture, rls, rpcs,
docker, next-steps, and READMEs.

Verified: build clean, all views + flows browser-tested, Docker build +
proxy + login + admin guard confirmed. DB reset to clean seed.
This commit is contained in:
Lago committed 2026-08-22 19:47:22 +02:00
1 parent 0cbfb25714
commit cf70f39903
45 files changed
+4425 -87

No files matched your search

+1
View File
@@ -34,5 +34,6 @@ Postgres 17 ── schema (9 tables)
## Source of truth
- Schema + RPCs + RLS: [`supabase/migrations/20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql)
- Admin app (Phase 2): admin read RLS + `reset_qr_token` RPC — [`supabase/migrations/20260823000000_admin_app.sql`](../../supabase/migrations/20260823000000_admin_app.sql)
- Seed: [`supabase/seed.sql`](../../supabase/seed.sql)
- Stack config: [`supabase/config.toml`](../../supabase/config.toml)
+31 -21
View File
@@ -4,12 +4,14 @@ Docker is the backbone. Two pieces:
1. **The Supabase core** — a set of containers managed by the **Supabase CLI**
(not by a compose file in this repo). See [supabase-core.md](./supabase-core.md).
2. **The app sidecar** — a single container built from
[`apps/convivo/Dockerfile`](../../apps/convivo/Dockerfile) and orchestrated by
the root [`docker-compose.yml`](../../docker-compose.yml).
2. **The app sidecars** — two containers, the attendee app
([`apps/convivo/Dockerfile`](../../apps/convivo/Dockerfile), `:3000`) and the
admin console ([`apps/admin/Dockerfile`](../../apps/admin/Dockerfile), `:3001`),
orchestrated by the root [`docker-compose.yml`](../../docker-compose.yml).
The app container **joins the network the CLI created** for the core and proxies
the Supabase same-origin paths to the Kong container.
Each app container **joins the network the CLI created** for the core and proxies
the Supabase same-origin paths to the Kong container. Both use the identical
multi-stage build + nginx proxy pattern (only the port and build context differ).
## How the pieces fit
@@ -21,10 +23,13 @@ flowchart LR
subgraph Net["supabase_network_Convivo (external)"]
K["supabase_kong_Convivo<br/>:8000 (internal)"]
APP["convivo-app<br/>nginx :3000"]
ADM["convivo-admin<br/>nginx :3001"]
end
CLI -.creates.-> Net
APP -->|"proxy /auth /rest /realtime /storage"| K
ADM -->|"proxy /auth /rest /realtime /storage"| K
APP -->|"host port 3000"| U["Browser"]
ADM -->|"host port 3001"| U
```
## The app image (`apps/convivo/Dockerfile`)
@@ -62,15 +67,17 @@ same-origin paths to the core:
## Root `docker-compose.yml`
Runs **only the app** (the core is CLI-managed). Key settings:
Runs **only the apps** (the core is CLI-managed). There are two services —
`convivo-app` (`:3000`) and `convivo-admin` (`:3001`) — with identical settings
except the build context and port:
| Setting | Value | Why |
|---|---|---|
| `build.context` | `./apps/convivo` | Builds the app image |
| `ports` | `3000:3000` | The app on the host |
| `environment.SUPABASE_PROXY_TARGET` | `supabase_kong_Convivo:8000` (default) | Where nginx proxies |
| `networks.supabase` | **external**, name `supabase_network_Convivo` | Joins the CLI-created network |
| `healthcheck` | `wget http://127.0.0.1:3000/` | Container reports healthy |
| Setting | `convivo-app` | `convivo-admin` | Why |
|---|---|---|---|
| `build.context` | `./apps/convivo` | `./apps/admin` | Builds the app image |
| `ports` | `3000:3000` | `3001:3001` | The app on the host |
| `environment.SUPABASE_PROXY_TARGET` | `supabase_kong_Convivo:8000` (default) | same | Where nginx proxies |
| `networks.supabase` | **external**, name `supabase_network_Convivo` | same | Joins the CLI-created network |
| `healthcheck` | `wget http://127.0.0.1:3000/` | `wget http://127.0.0.1:3001/` | Container reports healthy |
> If you change `project_id` in `supabase/config.toml`, update the external
> network name (`supabase_network_<project_id>`) and the default proxy target
@@ -85,25 +92,28 @@ npm run db:start
# 2. (Optional) reset to clean seed data
npm run db:reset
# 3. Build + run the app sidecar on :3000
# 3. Build + run both app sidecars (:3000 + :3001)
docker compose up --build
```
Open **http://localhost:3000**.
Open **http://localhost:3000** (attendee) and **http://localhost:3001** (admin).
### Alternative: dev server (no app container)
For faster iteration you can skip the app container and use the Vite dev server,
which proxies the same paths to `127.0.0.1:54321` (host port):
For faster iteration you can skip the app containers and use the Vite dev
servers, which proxy the same paths to `127.0.0.1:54321` (host port):
```bash
npm run db:start
npm run app:dev # Vite on :3000
npm run app:dev # attendee Vite on :3000
npm run admin:dev # admin Vite on :3001
```
## Verified behavior
- `docker compose build` → `npm ci` + `tsc` + `vite build` all pass in-container.
- `GET /` → HTTP 200 (SPA served by nginx).
- `docker compose build` → `npm ci` + `tsc` + `vite build` all pass in-container
(both `convivo-app` and `convivo-admin`).
- `GET /` → HTTP 200 (SPA served by nginx) on both `:3000` and `:3001`.
- `GET /auth/v1/health` through the proxy → GoTrue health JSON (proxy works).
- Full login (QR + email) works through the Docker-served app.
- Full login (QR + email) works through the Docker-served apps, including the
admin console's admin-role guard.
+18 -6
View File
@@ -37,13 +37,18 @@ Two `security definer` functions drive role checks (see [rpcs.md](./rpcs.md#role
| `profiles` | own **or** admin | — | admin only | admin only |
| `slots` | all authenticated | admin only | admin only | admin only |
| `sessions` | all authenticated | admin only | admin only | admin only |
| `preferences` | own (`profile_id = auth.uid()`) | — | — | — |
| `connections` | rows you're in (`from_id` or `to_id` = you) | — | — | — |
| `preferences` | own **or** admin | — | — | — |
| `connections` | rows you're in **or** admin | — | — | — |
| `checkins` | own **or** staff/admin | — | — | — |
| `feedback` | own | — | — | — |
| `feedback` | own **or** admin | — | — | — |
| `leaderboard` | all authenticated | — | — | — |
| `points_log` | own **or** admin | — | — | — |
> **Phase 2 addition** ([`20260823000000_admin_app.sql`](../../supabase/migrations/20260823000000_admin_app.sql)):
> admin-only `select` policies were added to `preferences`, `connections`, and
> `feedback` so the Admin console can read the full activity. The per-user
> policies above are unchanged — these are additive `OR is_admin()` reads.
**"—" (no policy)** means normal users have **no direct write access** — those
tables are written only by the `security definer` RPCs, which bypass RLS. This is
deliberate: a client cannot `UPDATE profiles SET points = 9999` or insert its own
@@ -89,6 +94,12 @@ create policy "leaderboard_select_all" on public.leaderboard for select to authe
-- points_log: read own or admin
create policy "points_log_select_own_or_admin" on public.points_log for select to authenticated
using (profile_id = auth.uid() or public.is_admin());
-- Phase 2 (20260823000000_admin_app.sql): additive admin-only reads for the
-- Admin console. These OR with the per-user policies above.
create policy "prefs_select_admin" on public.preferences for select to authenticated using (public.is_admin());
create policy "conn_select_admin" on public.connections for select to authenticated using (public.is_admin());
create policy "feedback_select_admin" on public.feedback for select to authenticated using (public.is_admin());
```
## GRANTs
@@ -113,9 +124,10 @@ full DML at the Postgres level, but **RLS narrows it** to the policies above.
internally, e.g. only staff can call `checkin_attendee`).
- **Staff** — everything an attendee can do, plus can read all `checkins` and call
the check-in RPC.
- **Admin** — full read on everything, and the only role with **direct** write
access to `profiles` / `slots` / `sessions` (this is what the future Admin app
in Phase 2 will use).
- **Admin** — full read on everything (including all `preferences`,
`connections`, and `feedback`), and the only role with **direct** write access
to `profiles` / `slots` / `sessions`. This is exactly what the Admin console
(Phase 2, [`../frontend/admin-app.md`](../frontend/admin-app.md)) uses.
## Things to revisit later
+22 -2
View File
@@ -104,8 +104,28 @@ Post-session feedback.
- Otherwise inserts and awards `earned` (category `feedback`).
### `adjust_points(p_profile_id, p_delta, p_reason)` → `void`
**Admin-only** manual points adjustment (category `admin`). Used by the future
Admin app (Phase 2).
**Admin-only** manual points adjustment (category `admin`). Used by the Admin
console (Phase 2) to award prizes or correct mistakes. Goes through
`_award_points`, so it floors at 0, writes `points_log`, and re-syncs the
leaderboard.
### `reset_qr_token(p_profile_id)` → `(profile_id, qr_token)`
**Admin-only.** Regenerates an attendee's lanyard QR token.
- Generates a fresh `CVV-XXX-NNNN` token and writes it to `profiles.qr_token`.
- **Re-hashes it as the Auth password** (`extensions.crypt(token, extensions.gen_salt('bf'))`
on `auth.users.encrypted_password`), so the **old token stops working** and the
attendee must re-scan with the new one.
- **Deletes the attendee's existing `auth.sessions`**, forcing a re-login.
- Returns the new token so the admin can print/show it as a QR code.
> **Implementation note:** pgcrypto's `gen_salt` / `crypt` live in the
> `extensions` schema (not `public`), so the function — whose `search_path` is
> pinned to `public` — must qualify them as `extensions.gen_salt(...)` /
> `extensions.crypt(...)`. The function owner (`postgres`) can write
> `auth.users` and `auth.sessions`, which is what makes this possible.
Source of truth for this RPC:
[`supabase/migrations/20260823000000_admin_app.sql`](../../supabase/migrations/20260823000000_admin_app.sql).
## Role helper functions