# 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` / `admin@appe.at`. ## 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.