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
+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.
|
||||
Reference in new issue
Block a user