feat: add magic-link admin login and speaker materials portal

This commit is contained in:
Lago committed 2026-10-07 18:27:56 +02:00
1 parent 3adc0fd58f
commit 8d8d3ae4b8
28 files changed
+1623 -232

No files matched your search

+57 -11
View File
@@ -3,8 +3,9 @@
The admin console is a **desktop-first single-page React app** in
[`apps/admin/`](../../apps/admin/), branded **APPE 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 `is_admin` flag** — anyone else who signs in is
immediately signed out.
pattern). Its admin gate accepts an existing contact with **`is_admin = true`
or an `@appe.at` email**, matching the database admin rule; other accounts are
signed out. Backend RLS remains the authorization boundary.
It runs on **port 3001** (Vite dev) or as the `convivo-admin` Docker container
(nginx). The attendee app stays on 3000.
@@ -24,19 +25,64 @@ It runs on **port 3001** (Vite dev) or as the `convivo-admin` Docker container
## Auth guard
Login is **email + password** (`signInWithPassword({ email, password })`), but
`AuthContext` checks the contact's `is_admin` flag after signing in:
Login uses **email-only magic links**, with no password field, sign-in method
selector, password fallback, or password-change prompt. `AuthContext` checks
the contact after signing in:
- If `is_admin === true` → the session is accepted and the console is shown.
- If `is_admin === true` or the contact email ends in `@appe.at` → 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 password is **event-independent** — it is the contact's Auth password
(`contacts.password` must match the bcrypt hash in `auth.users.encrypted_password`),
so the same admin can log in for any event. The seeded staff are
`[email protected]`, `[email protected]`, `[email protected]`, and `[email protected]`, all
with password `appe-admin-2026` (see [../backend/seed.md](../backend/seed.md)).
### Magic links
The email-only form calls `signInWithOtp` with `shouldCreateUser: false` and
`emailRedirectTo: <current Admin origin>/auth/callback`. It does not create
accounts or grant admin privileges. Eligible accounts must already exist in
Supabase Auth and have a matching contact. Account-related send failures show
the same generic confirmation as success; rate limits, network failures and
server failures show a generic retry error instead of server details. The
recipient is locked while sending, and resend has a 60-second UI
cooldown. A failed resend clears the previous confirmation.
`/auth/callback` accepts implicit-flow access/refresh tokens in the fragment,
or a PKCE `code` query parameter when a verifier exists in the same browser.
The callback is consumed once even under React StrictMode. It removes query
parameters and fragments from browser history before exchanging credentials,
ignores supplied `next`/`redirect_to` destinations, and always returns to `/`.
Invalid, expired or rejected links clear the local Auth session and allow a new
link request. The default client uses implicit flow and
`detectSessionInUrl: false`; the callback performs session handling explicitly.
A token-hash `/auth/confirm` email template is not supported by this handler.
Auth-state listeners defer Supabase calls with `setTimeout` rather than awaiting
them inside `onAuthStateChange`, avoiding Auth lock deadlocks. Revision checks
discard outdated listener/session-restore lookups after later auth events.
Vite proxies only `/auth/v1` so the SPA owns `/auth/callback`; nginx serves the
callback with `Cache-Control: no-store` and `Referrer-Policy: no-referrer`.
Local redirect allowlisting, Mailpit, and explicit production SMTP/URL setup are
documented in [Supabase Core](../backend/supabase-core.md#magic-link-configuration).
`admin.appe.at` is an intended production domain, not a verified deployment.
Focused browser coverage (mocked Auth/REST; no real email or database writes):
```bash
npm --prefix apps/admin run build
npm --prefix e2e test -- admin-magic-link.spec.ts
```
The spec defaults to `http://localhost:3001`; set `CONVIVO_ADMIN_URL` to test an
alternate local server. Real delivery and Supabase redirect enforcement require
a separate local Mailpit smoke test after restarting the local Auth service.
This is an **Admin frontend-only** change. Existing database passwords, password
sync triggers, shared password operations and Supabase Auth's password endpoint
remain unchanged because attendee/staff login still uses them. Admin sessions
remain event-independent, and contacts with existing default passwords do not
receive a password-change prompt. See [demo accounts](../backend/seed.md#demo-accounts)
for seeded staff credentials used by the Convivo app.
## Source layout
@@ -55,7 +101,7 @@ apps/admin/src/
├─ components/
│ └─ ui.tsx # Avatar, Spinner, Empty, Modal, QrImage, TypeBadge, Toggle
├─ screens/
│ └─ Login.tsx # email + password login (admin-only)
│ └─ Login.tsx # email-only magic-link login (admin-only)
└─ views/
├─ Dashboard.tsx # active event + aggregates + top points + activity
├─ Contacts.tsx # table + edit / is_admin / visibility / points
+33 -1
View File
@@ -55,7 +55,7 @@ These map 1:1 to the Postgres RPCs documented in
| `submitFeedback(sessionId, rating, comment)` | `submit_feedback` | Rate a session (+5/+10) |
| `getLeaderboard()` | `get_leaderboard` | Active-event leaderboard |
| `uploadSessionMaterial(sessionId, file)` | `set_session_material` | Upload to `materials` bucket + set `material_path` |
| `removeSessionMaterial(sessionId)` | `set_session_material` | Delete storage object + clear `material_path` (speakers) |
| `removeSessionMaterial(sessionId)` | `set_session_material` | Clear `material_path`, then delete the detached storage object |
| `updateMyProfile({linkedin_url, show_email, show_linkedin})` | `update_my_profile` | Self-service: set LinkedIn + visibility toggles on the caller's own contact |
### Direct table reads (RLS-scoped)
@@ -82,6 +82,38 @@ client-side to avoid leaking other people's data:
- **`sessionMaterialUrl(path)`** — builds the public URL for a session material
in the `materials` bucket.
## Speaker Portal
[speakerPortal.ts](../../apps/convivo/src/lib/speakerPortal.ts) recognizes only
`/speaker/secret` and `/speaker` (optional trailing slash). It exposes a shared
`speakerPortalSession` promise, consuming implicit token pairs with `setSession`
or PKCE codes with `exchangeCodeForSession` exactly once per page load, including
React StrictMode. Automatic URL session detection remains disabled. Callback
parameters are scrubbed before auth calls; errors use generic recoverable text.
`SpeakerPortal` requests `signInWithOtp` with `shouldCreateUser: false` and
`emailRedirectTo: window.location.origin + '/speaker/secret'`. Supabase Auth's
redirect allowlist must include this URL on each deployment origin. This does
not create contacts, registrations or Auth users.
`getSpeakerPortalSessions()` calls `get_my_speaker_sessions`, returning typed
`SpeakerSession` rows with talk/material, event and slot information. Authorization
is [backend-owned](../backend/rls.md#speaker-portal-authorization); the client
does not filter by active event, clock, points or physical check-in.
Material helpers are shared with Agenda. Upload reads the previous path, creates
a unique `sessions/<session UUID>/<random UUID>-<sanitized filename>` object,
then calls `set_session_material`. A rejected attachment removes the new object.
After successful replacement, the previous object is removed. Removal detaches
the path first, then deletes the old object. Cleanup errors distinguish a saved
or detached material from a failed attachment; the portal refreshes the list
after each attempted operation. These Storage and RPC calls are not one atomic
transaction, so simultaneous clients remain last-writer-wins and can leave an
unattached object; they never mutate attendance or points.
See [RPC contract](../backend/rpcs.md#speaker-portal-rpcs),
[screen states](./screens.md#speaker-portal) and [tests](../backend/tests.md#speaker-portal).
## Types (`lib/types.ts`)
TypeScript interfaces mirroring the DB tables and RPC return shapes
+31 -3
View File
@@ -3,8 +3,9 @@
Every screen in [`apps/convivo/src/screens/`](../../apps/convivo/src/screens/).
All screens are mobile-first and use the shared UI components
([app-structure.md#shared-ui-components](./app-structure.md#shared-ui-components)).
Data comes from the typed [api client](./api-client.md); the current user comes
from `useAuth()` (`contact` + `registration`).
Data comes from the typed [api client](./api-client.md); the normal app's current
user comes from `useAuth()` (`contact` + `registration`). The speaker portal
uses its own auth lifecycle and backend-scoped session list.
| Screen | File | Reach |
|---|---|---|
@@ -17,6 +18,33 @@ from `useAuth()` (`contact` + `registration`).
| Leaderboard | `Leaderboard.tsx` | from Home (points pill / quick action) |
| Feedback | `Feedback.tsx` | full-screen takeover from Agenda |
| EventFeedback | `EventFeedback.tsx` | full-screen takeover from Home ("Rate this event") |
| Speaker Portal | [SpeakerPortal.tsx](../../apps/convivo/src/screens/SpeakerPortal.tsx) | `/speaker/secret` (also `/speaker`) |
## Speaker Portal
An email-only magic-link login for **existing Auth users**. The canonical
redirect is `/speaker/secret`; `/speaker` is also accepted. Neither route is a
secret credential: authorization is enforced by the backend. Failed/expired
callbacks show a recoverable error and callback tokens/codes are removed from
the address bar. Callback consumption is shared across StrictMode mounts.
Signed-in users see only their own assigned non-service talks with a `speaker`
or `staff` registration for the corresponding event. Admin/organizer staff can
also speak while retaining their staff category; service-slot assignments are excluded.
The list spans all events, including
inactive, past and future events. No physical check-in is required. An empty
list grants no material controls; access/load failures offer retry.
Each talk shows event, date/time, room and material status, with upload,
replacement, download and confirmed removal. Uploads accept non-empty PDF,
PowerPoint, ODP, ZIP and TXT files up to 50 MB. Controls are disabled during a
material operation; failures reload server state. Signing out is local to the
browser session.
Portal operations never mark attendance or award points. Visiting `/` still
uses the normal app's check-in gate. See [portal API behavior](./api-client.md#speaker-portal),
[authorization](../backend/rls.md#speaker-portal-authorization) and
[regression coverage](../backend/tests.md#speaker-portal).
## Login
@@ -39,7 +67,7 @@ A 3-step flow: **splash → scan → confirm**.
mismatch, an error is shown ("Email and QR code do not match" for attendees,
"That password is incorrect" for staff).
> No email is ever sent. See
> This normal QR login sends no email; the separate speaker portal uses magic links. See
> [../architecture.md#6-authentication-model](../architecture.md#6-authentication-model)
> and [../backend/rls.md](../backend/rls.md).