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:
1 parent
0cbfb25714
commit
cf70f39903
45 files changed
+4425
-87
No files matched your search
+11
-7
@@ -4,8 +4,8 @@ Living documentation for **Convivo** — a conference networking app that turns
|
||||
conference into a game. This folder is the single source of truth for *how the
|
||||
system works*; the root [`README.md`](../README.md) is the quick-start.
|
||||
|
||||
> **Status:** Phase 0 (Dockerized Supabase core) + Phase 1 (attendee web PWA)
|
||||
> are complete and verified. Phases 2–4 are planned — see
|
||||
> **Status:** Phase 0 (Dockerized Supabase core) + Phase 1 (attendee web PWA) +
|
||||
> Phase 2 (admin console) are complete and verified. Phases 3–4 are planned — see
|
||||
> [next-steps.md](./next-steps.md).
|
||||
|
||||
## Where things live
|
||||
@@ -20,11 +20,12 @@ system works*; the root [`README.md`](../README.md) is the quick-start.
|
||||
| Row Level Security policies | [backend/rls.md](./backend/rls.md) |
|
||||
| Seed data + demo accounts | [backend/seed.md](./backend/seed.md) |
|
||||
| Docker (app image + compose) | [backend/docker.md](./backend/docker.md) |
|
||||
| **Frontend (attendee PWA) — overview** | [frontend/README.md](./frontend/README.md) |
|
||||
| App structure, state, contexts, routing | [frontend/app-structure.md](./frontend/app-structure.md) |
|
||||
| Every screen (Login, Home, Agenda, Scan, …) | [frontend/screens.md](./frontend/screens.md) |
|
||||
| **Frontend — overview (both apps)** | [frontend/README.md](./frontend/README.md) |
|
||||
| Attendee app: structure, state, contexts, routing | [frontend/app-structure.md](./frontend/app-structure.md) |
|
||||
| Attendee app: every screen (Login, Home, Agenda, Scan, …) | [frontend/screens.md](./frontend/screens.md) |
|
||||
| API client (how the app talks to Supabase) | [frontend/api-client.md](./frontend/api-client.md) |
|
||||
| **What's next (Phase 2/3/4 + open items)** | [next-steps.md](./next-steps.md) |
|
||||
| **Admin console** (views, auth guard, QR reset, points, schedule) | [frontend/admin-app.md](./frontend/admin-app.md) |
|
||||
| **What's next (Phase 3/4 + open items)** | [next-steps.md](./next-steps.md) |
|
||||
|
||||
## Reading order
|
||||
|
||||
@@ -35,6 +36,7 @@ system works*; the root [`README.md`](../README.md) is the quick-start.
|
||||
[backend/rls.md](./backend/rls.md).
|
||||
3. **Working on the UI?** Go to [frontend/app-structure.md](./frontend/app-structure.md)
|
||||
→ [frontend/screens.md](./frontend/screens.md) → [frontend/api-client.md](./frontend/api-client.md).
|
||||
For the admin console, read [frontend/admin-app.md](./frontend/admin-app.md).
|
||||
4. **Planning the next phase?** Read [next-steps.md](./next-steps.md).
|
||||
|
||||
## Conventions
|
||||
@@ -45,7 +47,9 @@ system works*; the root [`README.md`](../README.md) is the quick-start.
|
||||
- **Code is the source of truth.** If a doc and the code disagree, the code wins —
|
||||
fix the doc. Key files:
|
||||
- Schema + RPCs + RLS: [`supabase/migrations/20260822000000_init.sql`](../supabase/migrations/20260822000000_init.sql)
|
||||
- Admin app migration (admin read RLS + `reset_qr_token`): [`supabase/migrations/20260823000000_admin_app.sql`](../supabase/migrations/20260823000000_admin_app.sql)
|
||||
- Seed: [`supabase/seed.sql`](../supabase/seed.sql)
|
||||
- App source: [`apps/convivo/src/`](../apps/convivo/src/)
|
||||
- Attendee app source: [`apps/convivo/src/`](../apps/convivo/src/)
|
||||
- Admin app source: [`apps/admin/src/`](../apps/admin/src/)
|
||||
- **Keep it current.** Update the relevant doc in the same change that changes the
|
||||
behavior it describes.
|
||||
+30
-6
@@ -16,14 +16,18 @@ make connections, get checked in by staff, and rate sessions. Every action earns
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
subgraph Browser["Browser (attendee / staff phone)"]
|
||||
subgraph Browser["Browser"]
|
||||
A["Convivo PWA<br/>React 18 + Vite 5 + TS<br/>mobile-first, installable"]
|
||||
AD["Convivo Admin<br/>React 18 + Vite 5 + TS<br/>desktop-first console"]
|
||||
end
|
||||
|
||||
subgraph Docker["Docker (local)"]
|
||||
subgraph AppC["convivo-app container (:3000)"]
|
||||
N["nginx<br/>serves SPA + proxies Supabase paths"]
|
||||
end
|
||||
subgraph AdminC["convivo-admin container (:3001)"]
|
||||
NA["nginx<br/>serves SPA + proxies Supabase paths"]
|
||||
end
|
||||
subgraph Core["Supabase core (Supabase CLI)"]
|
||||
K["Kong API gateway<br/>:54321"]
|
||||
K --> G["GoTrue (Auth)"]
|
||||
@@ -37,7 +41,9 @@ flowchart LR
|
||||
end
|
||||
|
||||
A -->|"same-origin /auth /rest /realtime /storage"| N
|
||||
AD -->|"same-origin /auth /rest /realtime /storage"| NA
|
||||
N -->|"proxy (supabase_kong_Convivo:8000)"| K
|
||||
NA -->|"proxy (supabase_kong_Convivo:8000)"| K
|
||||
```
|
||||
|
||||
**Key idea:** there is **no custom backend**. Supabase provides auth, data,
|
||||
@@ -72,6 +78,16 @@ A single-page React app with a tab shell and a few full-screen takeovers. See
|
||||
- **Screens** — Login, Home, Agenda, Scan/Check-in, Connections, Feedback, Leaderboard, Profile. → [frontend/screens.md](./frontend/screens.md)
|
||||
- **API client** — a thin typed wrapper over `supabase.rpc` / `supabase.from`. → [frontend/api-client.md](./frontend/api-client.md)
|
||||
|
||||
### Frontend — the admin console
|
||||
A separate desktop-first React app for organizers, guarded to the **admin** role.
|
||||
See [frontend/admin-app.md](./frontend/admin-app.md):
|
||||
- **Views** — Dashboard (live stats), Attendees (edit / reset QR / adjust
|
||||
points), Schedule (manage slots + sessions), Activity (check-ins /
|
||||
connections / feedback).
|
||||
- **Auth guard** — same QR + email login, but non-admin sessions are rejected.
|
||||
- **New RPC** — `reset_qr_token` regenerates an attendee's lanyard token and
|
||||
syncs the Auth password (see [backend/rpcs.md](./backend/rpcs.md)).
|
||||
|
||||
## 5. How a request flows (example: staff check-in)
|
||||
|
||||
```mermaid
|
||||
@@ -113,7 +129,8 @@ the work atomically, and the `leaderboard` table change fans out over Realtime.
|
||||
| Service | Port | Notes |
|
||||
|---|---|---|
|
||||
| **Convivo app** | **3000** | Vite dev server (dev) or nginx (Docker) |
|
||||
| Supabase API (Kong) | 54321 | The single gateway the app proxies to |
|
||||
| **Convivo admin** | **3001** | Vite dev server (dev) or nginx (Docker) |
|
||||
| Supabase API (Kong) | 54321 | The single gateway the apps proxy to |
|
||||
| Supabase Studio | 54323 | UI — login `postgres` / `postgres` |
|
||||
| Postgres | 54322 | Direct DB access (`postgres` / `postgres`) |
|
||||
| SMTP (Mailpit) | 54324 | Captures emails (none are sent in this flow) |
|
||||
@@ -122,9 +139,10 @@ the work atomically, and the `leaderboard` table change fans out over Realtime.
|
||||
```bash
|
||||
npm run db:start # start the Supabase core (Docker)
|
||||
npm run db:reset # (re)apply migrations + seed
|
||||
npm run app:dev # dev server on :3000
|
||||
npm run app:dev # attendee dev server on :3000
|
||||
npm run admin:dev # admin dev server on :3001
|
||||
# — or —
|
||||
docker compose up --build # app as a Docker sidecar on :3000
|
||||
docker compose up --build # both apps as Docker sidecars (:3000 + :3001)
|
||||
```
|
||||
|
||||
## 8. The demo clock
|
||||
@@ -142,11 +160,17 @@ Convivo/
|
||||
│ ├─ Dockerfile # Multi-stage: build → nginx
|
||||
│ ├─ nginx.conf.template # SPA + same-origin proxy to the Supabase core
|
||||
│ └─ src/ # screens, components, lib, context
|
||||
├─ apps/admin/ # Admin console (React + Vite + TS, desktop-first)
|
||||
│ ├─ Dockerfile # Multi-stage: build → nginx
|
||||
│ ├─ nginx.conf.template # SPA + same-origin proxy to the Supabase core
|
||||
│ └─ src/ # views, components, lib, context
|
||||
├─ supabase/
|
||||
│ ├─ config.toml # Local stack config (ports, auth, RLS defaults)
|
||||
│ ├─ migrations/ # 20260822000000_init.sql — schema, RLS, RPCs
|
||||
│ ├─ migrations/
|
||||
│ │ ├─ 20260822000000_init.sql # schema, RLS, points RPCs
|
||||
│ │ └─ 20260823000000_admin_app.sql # admin read RLS + reset_qr_token RPC
|
||||
│ └─ seed.sql # Slots, sessions, 13 demo users, Ana's demo state
|
||||
├─ docker-compose.yml # Runs the app sidecar on the Supabase network
|
||||
├─ docker-compose.yml # Runs both app sidecars on the Supabase network
|
||||
├─ docs/ # ← this documentation
|
||||
└─ mockup/index.html # Original interactive mockup (design reference)
|
||||
```
|
||||
@@ -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
@@ -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
@@ -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
@@ -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
|
||||
|
||||
|
||||
+14
-7
@@ -1,15 +1,22 @@
|
||||
# Frontend — Attendee PWA
|
||||
# Frontend
|
||||
|
||||
The frontend is a **mobile-first single-page React app** (PWA) in
|
||||
[`apps/convivo/`](../../apps/convivo/). It is the same app for attendees, staff,
|
||||
and admins — the user's `role` changes what they see (e.g. the Scan tab becomes a
|
||||
Check-in tab for staff).
|
||||
There are **two** React apps, both talking to the same Supabase core through
|
||||
same-origin paths:
|
||||
|
||||
- **Attendee PWA** — a mobile-first single-page app in
|
||||
[`apps/convivo/`](../../apps/convivo/). The same app for attendees, staff, and
|
||||
admins — the user's `role` changes what they see (e.g. the Scan tab becomes a
|
||||
Check-in tab for staff).
|
||||
- **Admin console** — a desktop-first app in
|
||||
[`apps/admin/`](../../apps/admin/), guarded to the `admin` role. See
|
||||
[admin-app.md](./admin-app.md).
|
||||
|
||||
| File | What it covers |
|
||||
|---|---|
|
||||
| [app-structure.md](./app-structure.md) | Entry, contexts, the event hook, the tab shell, the demo clock |
|
||||
| [screens.md](./screens.md) | Every screen: Login, Home, Agenda, Scan/Check-in, Connections, Feedback, Leaderboard, Profile |
|
||||
| [app-structure.md](./app-structure.md) | Attendee app: entry, contexts, the event hook, the tab shell, the demo clock |
|
||||
| [screens.md](./screens.md) | Attendee app: Login, Home, Agenda, Scan/Check-in, Connections, Feedback, Leaderboard, Profile |
|
||||
| [api-client.md](./api-client.md) | The typed API wrapper + how the app talks to Supabase (auth, REST, realtime) |
|
||||
| [admin-app.md](./admin-app.md) | Admin console: views, the admin auth guard, QR reset, points, schedule |
|
||||
|
||||
## Tech
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
# Frontend — Admin console
|
||||
|
||||
The admin console is a **desktop-first single-page React app** in
|
||||
[`apps/admin/`](../../apps/admin/). It is a separate app from the attendee PWA
|
||||
(same stack, same Supabase core, same same-origin proxy pattern) and is **guarded
|
||||
to the `admin` role** — anyone else who signs in is immediately signed out.
|
||||
|
||||
It runs on **port 3001** (Vite dev) or as the `convivo-admin` Docker container
|
||||
(nginx). The attendee app stays on 3000.
|
||||
|
||||
## What it does
|
||||
|
||||
| View | Purpose |
|
||||
|---|---|
|
||||
| **Dashboard** | Live event stats (attendees, check-ins, connections, avg rating, sessions) + top points + recent activity. |
|
||||
| **Attendees** | Searchable table of all people. Edit name/company/role, view + **reset the QR token**, and **adjust points**. |
|
||||
| **Schedule** | Manage **slots** and **sessions** — create, edit, delete. |
|
||||
| **Activity** | Tables of check-ins, connections, and feedback. |
|
||||
|
||||
## Auth guard
|
||||
|
||||
Login is the same QR + email flow as the attendee app
|
||||
(`signInWithPassword({ email, password: qrToken })`), but `AuthContext` checks the
|
||||
profile's `role` after signing in:
|
||||
|
||||
- If `role === 'admin'` → the session is accepted and the console is shown.
|
||||
- Otherwise → the app calls `signOut()` and shows **"This account is not an
|
||||
admin."** The same check runs on session restore (page reload) and on every
|
||||
`onAuthStateChange`, so a non-admin can never see the console.
|
||||
|
||||
The demo admin is `CVV-ADM-0001` / `[email protected]`.
|
||||
|
||||
## Source layout
|
||||
|
||||
```
|
||||
apps/admin/src/
|
||||
├─ main.tsx # ReactDOM entry
|
||||
├─ App.tsx # Providers + Shell (sidebar nav + view switch)
|
||||
├─ styles.css # Desktop-first styling (same design tokens as the PWA)
|
||||
├─ context/
|
||||
│ ├─ AuthContext.tsx # session + profile + admin-role guard
|
||||
│ └─ ToastContext.tsx # transient toasts
|
||||
├─ lib/
|
||||
│ ├─ supabase.ts # createClient (same-origin)
|
||||
│ ├─ api.ts # typed wrapper: reads + updateProfile / adjustPoints / resetQrToken
|
||||
│ └─ types.ts # TS types mirroring the DB
|
||||
├─ components/
|
||||
│ └─ ui.tsx # Avatar, Spinner, Empty, Modal, QrImage, RoleBadge
|
||||
├─ screens/
|
||||
│ └─ Login.tsx # QR + email login (admin-only)
|
||||
└─ views/
|
||||
├─ Dashboard.tsx # stats + top points + recent activity
|
||||
├─ Attendees.tsx # table + edit / QR-reset / points modals
|
||||
├─ Schedule.tsx # slots + sessions CRUD
|
||||
└─ Activity.tsx # check-ins / connections / feedback tables
|
||||
```
|
||||
|
||||
## Data access
|
||||
|
||||
The admin app uses the **anon key + the admin's session JWT** — no service-role
|
||||
key. Everything it can do is allowed by RLS:
|
||||
|
||||
- **Reads** — admin-only `select` policies on `profiles`, `connections`,
|
||||
`feedback`, `preferences`, `checkins`, `points_log`, plus the public
|
||||
`slots` / `sessions` / `leaderboard`. See [../backend/rls.md](../backend/rls.md).
|
||||
- **Writes** — direct `insert` / `update` / `delete` on `profiles`, `slots`, and
|
||||
`sessions` (admin-only policies).
|
||||
- **RPCs** — `reset_qr_token` (regenerate a lanyard token) and `adjust_points`
|
||||
(manual, audited as `admin`). See [../backend/rpcs.md](../backend/rpcs.md).
|
||||
|
||||
### Resetting a QR token
|
||||
|
||||
`reset_qr_token(profile_id)` generates a new `CVV-XXX-NNNN` token, writes it to
|
||||
`profiles.qr_token`, **re-hashes it as the Auth password** (so the old token stops
|
||||
working), and deletes the attendee's existing sessions (forcing a re-login). The
|
||||
UI shows the new token as a scannable QR code.
|
||||
|
||||
### Adjusting points
|
||||
|
||||
`adjust_points(profile_id, delta, reason)` is the same transactional RPC the
|
||||
event uses, but the `category` is `admin` so manual adjustments are auditable in
|
||||
`points_log`. It keeps `profiles.points` and the `leaderboard` mirror in sync.
|
||||
|
||||
## Styling
|
||||
|
||||
The admin app reuses the attendee app's **design tokens** (colors, Poppins font,
|
||||
card/pill/button styles) but is laid out **desktop-first**: a dark sidebar with
|
||||
the nav + admin identity, and a wide content area with stat cards and data
|
||||
tables. Below ~760px the sidebar collapses to a top bar so it still works on a
|
||||
phone.
|
||||
+23
-19
@@ -8,10 +8,10 @@ interface → **4** Sessionize interface.
|
||||
> sync), and the Pretix interface is **Phase 3**. (Originally the whiteboard had
|
||||
> Pretix as Phase 2 and the admin app as Phase 3.)
|
||||
|
||||
> **Current state:** Phase 0 + Phase 1 are **complete and verified** (browser-
|
||||
> tested end-to-end, Docker-verified, pushed to `git.lago.dev/Lago/Convivo.git`).
|
||||
> Per the working agreement, we **stop here** and let the user evaluate before
|
||||
> starting Phase 2.
|
||||
> **Current state:** Phase 0 + Phase 1 + Phase 2 are **complete and verified**
|
||||
> (browser-tested end-to-end, Docker-verified, pushed to
|
||||
> `git.lago.dev/Lago/Convivo.git`). Per the working agreement, we **stop here**
|
||||
> and let the user evaluate before starting Phase 3 (Pretix).
|
||||
|
||||
## Done
|
||||
|
||||
@@ -29,22 +29,27 @@ interface → **4** Sessionize interface.
|
||||
- All flows browser-tested; Docker build + proxy + login verified.
|
||||
- Details: [frontend/README.md](./frontend/README.md).
|
||||
|
||||
## Next
|
||||
|
||||
### Phase 2 — Admin app (admin.appe.at) ⬜ (next)
|
||||
A separate web app for event organizers, using the **admin** role (which already
|
||||
has direct write access to `profiles` / `slots` / `sessions` via RLS — see
|
||||
### Phase 2 — Admin app (admin.appe.at) ✅
|
||||
A separate desktop-first web app for event organizers, using the **admin** role
|
||||
(which has direct write access to `profiles` / `slots` / `sessions` via RLS — see
|
||||
[backend/rls.md](./backend/rls.md)).
|
||||
|
||||
Likely scope:
|
||||
- Manage **attendees** (view, edit role/company, reset QR, adjust points via
|
||||
`adjust_points`).
|
||||
- Manage **schedule** (slots + sessions) — create/edit/delete.
|
||||
- **Live overview** — who's checked in, connection activity, leaderboard.
|
||||
- Reuse the same Supabase core + anon/service key pattern; a new `apps/admin`
|
||||
PWA.
|
||||
- **Login** — same QR + email flow, but guarded: non-admin accounts are signed
|
||||
out and rejected ("This account is not an admin").
|
||||
- **Dashboard** — live stats (attendees, check-ins, connections, avg rating,
|
||||
sessions) + top points + recent activity.
|
||||
- **Attendees** — searchable table; edit name/company/role, view + **reset QR
|
||||
token** (new `reset_qr_token` RPC), **adjust points** (via `adjust_points`).
|
||||
- **Schedule** — manage slots + sessions (create/edit/delete).
|
||||
- **Activity** — check-ins, connections, and feedback tables.
|
||||
- Same-origin proxy to Supabase (Vite dev on :3001 / nginx in Docker).
|
||||
- Docker: `convivo-admin` service on :3001, same network + proxy pattern.
|
||||
- All views + flows browser-tested; Docker build + proxy + login verified.
|
||||
- Details: [frontend/admin-app.md](./frontend/admin-app.md).
|
||||
|
||||
### Phase 3 — Pretix interface ⬜
|
||||
## Next
|
||||
|
||||
### Phase 3 — Pretix interface ⬜ (next)
|
||||
Sync **tickets → attendees** from [Pretix](https://pretix.eu) (the ticketing
|
||||
system). This replaces the hand-written seed with real ticket data.
|
||||
|
||||
@@ -96,8 +101,7 @@ Likely scope:
|
||||
1. **Pretix role mapping** — which ticket type = staff/admin?
|
||||
2. **Sync style** — webhook (push) vs scheduled (pull) for Pretix/Sessionize?
|
||||
3. **Sync runtime** — Supabase Edge Functions vs separate containers?
|
||||
4. **Admin app scope** — which admin features are must-haves for the event?
|
||||
5. **Deployment target** — stay on localhost, or plan for the `appe.at`
|
||||
4. **Deployment target** — stay on localhost, or plan for the `appe.at`
|
||||
subdomains now?
|
||||
|
||||
## How to pick up work
|
||||
|
||||
Reference in new issue
Block a user