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