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

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
committed 2026-10-07 18:27:56 +02:00
1 parent 0b6d1f2b6f
commit 68fecc2ad1
28 files changed
+1623 -232

No files matched your search

+37 -4
View File
@@ -130,18 +130,51 @@ The `materials` bucket (public read) stores session material. Policies on
create policy "materials_read" on storage.objects for select to authenticated
using (bucket_id = 'materials');
create policy "materials_write" on storage.objects for insert to authenticated
with check (bucket_id = 'materials' and public.is_speaker_or_admin());
with check (bucket_id = 'materials' and public.can_write_session_material(name));
create policy "materials_update" on storage.objects for update to authenticated
using (bucket_id = 'materials' and public.is_speaker_or_admin());
using (bucket_id = 'materials' and public.can_write_session_material(name))
with check (bucket_id = 'materials' and public.can_write_session_material(name));
create policy "materials_delete" on storage.objects for delete to authenticated
using (bucket_id = 'materials' and public.is_speaker_or_admin());
using (bucket_id = 'materials' and public.can_write_session_material(name));
```
Speakers + admins can write; any authenticated attendee can read (download).
Registered speakers can write only their own non-service session paths; admins
retain material management access. Any authenticated attendee can read (download).
Because the `sessions` table is admin-write only, a speaker attaches their
uploaded file via the `set_session_material` RPC (see
[rpcs.md](./rpcs.md#set_session_materialp_session_id-p_material_path--sessions)).
## Speaker Portal Authorization
Source: [speaker portal migration](../../supabase/migrations/20261006175631_speaker_portal.sql),
with [staff overlap](../../supabase/migrations/20261007153957_speaker_portal_staff_overlap.sql).
`owns_speaker_session(session_id)` requires the JWT's `current_email()` to have
both a `session_speakers` assignment and a `registrations.type` of `speaker` or `staff`
for that session's event. The slot must belong to the same event and be type
`session`, not `service_session`. Assignment alone, registration alone,
attendee/sponsor assignments, or another speaker's registration is insufficient.
Admin/organizer staff can also speak without changing category or losing staff
points/check-in exclusions. There is no separate `organizer` enum value.
Automatic staff links to service slots do not grant portal ownership.
Admins retain global material management access, but the portal lists only their own talks.
Neither event activation, event date nor `checked_in` enters this predicate.
`can_write_session_material(path)` accepts speaker paths only in the form
`sessions/<UUID>/<non-empty filename>` and checks the referenced session's
ownership. UPDATE checks both old and new names, preventing reassignment to
foreign paths. Public material reads are intentionally unchanged.
The portal read and material setter are security-definer functions with an empty
search path and qualified object names. EXECUTE is revoked from PUBLIC/anon and
granted to authenticated/service_role; role membership alone does not grant
speaker access. The setter checks ownership again, locks the session row and
verifies a non-null object exists in `materials` under the exact session path.
It cannot update registrations, points logs, check-ins or leaderboard rows.
See [RPCs](./rpcs.md#speaker-portal-rpcs), [transactional tests](./tests.md#speaker-portal)
and [frontend entry points](../frontend/screens.md#speaker-portal). The normal
app's physical check-in gate remains separate and unchanged.
## GRANTs
The new Supabase CLI does **not** auto-expose new tables to the Data API roles, so
+35 -6
View File
@@ -18,8 +18,9 @@ Source of truth:
re-sync the leaderboard* in **one transaction**. Either all happen or none do.
- **Idempotent where it matters** → re-check-in and re-feedback are detected and
never double-award.
- **Event-scoped** → every RPC resolves the **active event** first and scopes all
reads/writes to it.
- **Event-scoped** → points RPCs resolve the **active event** first. Speaker
portal material RPCs instead authorize against the session's own event,
including inactive events.
## Points rules
@@ -201,10 +202,38 @@ placeholder string ("AI evaluation stub: N comment(s) received. (LLM integration
pending.)"). Real LLM integration is a later phase.
### `set_session_material(p_session_id, p_material_path)` → `sessions`
Sets a session's `material_path`. Allowed for **admins and for any speaker of the
session** (the `sessions` table is admin-write only, so speakers need this
security-definer RPC to attach their uploaded material). The attendee app calls
this after uploading a file to the `materials` bucket.
Sets only a session's `material_path`, with a row lock. Requires authentication
and either admin access or an own assignment plus `speaker` or `staff` registration for the
session's event and a non-service slot. For non-admins, non-null paths must be an
existing uploaded `materials` object under `sessions/<this session UUID>/<filename>`.
`NULL` detaches material. Ownership/path failures use SQLSTATE `42501`.
There is no active-event, date, check-in or points condition. Shared by Agenda and
the [speaker portal](../frontend/screens.md#speaker-portal).
## Speaker Portal RPCs
Source: [20261006175631_speaker_portal.sql](../../supabase/migrations/20261006175631_speaker_portal.sql),
with [staff overlap](../../supabase/migrations/20261007153957_speaker_portal_staff_overlap.sql).
- `get_my_speaker_sessions()` returns own registered non-service talks across
all events, ordered by slot date/time, event name, title and session ID. Rows
contain `session_id`, `title`, `description`, `room`, `material_path`,
`event_id`, `event_name`, `event_start_date`, `event_end_date`, `is_active`,
`slot_date`, `start_time`, `end_time`. Ineligible authenticated users get `[]`.
- `owns_speaker_session(uuid)` requires an explicit own talk assignment and a
same-event `speaker` or `staff` registration, including registered Admin staff.
Registration category remains unchanged; staff points/check-in exclusions remain intact.
- `can_write_session_material(text)` validates session object paths for Storage
INSERT/UPDATE/DELETE; admins retain their existing management access.
- `set_session_material(uuid, text)` follows the mutation contract above and
does not mark physical attendance or award points.
All four functions revoke PUBLIC/anon execution and grant authenticated/service_role
execution. See [RLS details](./rls.md#speaker-portal-authorization),
[client lifecycle](../frontend/api-client.md#speaker-portal) and
[regression tests](./tests.md#speaker-portal).
## Other RPCs
### `update_my_profile(p_linkedin_url, p_show_email, p_show_linkedin)` → `contacts`
**Self-service (any authenticated attendee).** Lets a contact edit their own
+7 -6
View File
@@ -65,21 +65,22 @@ Bootcamp (Austria)** — instead of random demo data:
**Attendees** log in with **QR code** (typed or scanned) + **email** — the QR
token is the Auth password. **Staff** log in with **QR code + their staff
password** in the Convivo app, or **email + password** in the admin app. All four
password** in the Convivo app. The Admin console uses only
[email magic links](../frontend/admin-app.md#auth-guard). All four
staff share the password **`appe-admin-2026`** (stored in `contacts.password`,
auto-synced to `auth.users.encrypted_password` by the `trg_contact_password_sync`
trigger).
> **Default admin password:** any `@appe.at` contact is an admin and logs in
> with **`appe-admin-2026`** out of the box. The `trg_contacts_appe_at_admin`
> **Existing default password:** any `@appe.at` contact is an admin and retains
> **`appe-admin-2026`** for Convivo staff password login. The `trg_contacts_appe_at_admin`
> trigger sets `contacts.password = 'appe-admin-2026'` (when null) on
> insert/update, and the auth-user-creation helpers hash it into
> `auth.users.encrypted_password` so a freshly-created `@appe.at` admin can log
> in immediately. A custom password set on the contact row is always respected
> `auth.users.encrypted_password`. Admin magic-link login neither uses nor changes
> these passwords. A custom password set on the contact row is always respected
> (never overwritten). See migration
> [`20260910000000_admin_default_password.sql`](../../supabase/migrations/20260910000000_admin_default_password.sql).
| Person | Type | Email | Login |
| Person | Type | Email | Convivo Login |
|---|---|---|---|
| **Amelia Hernandez** | staff (admin) | amelia@appe.at | `appe-admin-2026` |
| **Sabrina Hota** | staff (admin) | sabrina@appe.at | `appe-admin-2026` |
+136 -3
View File
@@ -17,7 +17,7 @@ the "main docker" of the project.
| `supabase_storage_Convivo` | `supabase/storage-api` | Storage — the `materials` bucket (session material) |
| `supabase_kong_Convivo` | `supabase/kong` | **API gateway** — fronts everything on one port |
| `supabase_studio_Convivo` | `supabase/studio` | Web UI (Studio) |
| `supabase_inbucket_Convivo` | `supabase/mailpit` | Captures emails (none sent in this flow) |
| `supabase_inbucket_Convivo` | `supabase/mailpit` | Local capture service; Auth bypasses it while custom SMTP is enabled |
| `supabase_pg_meta_Convivo` | `supabase/postgres-meta` | Metadata API (used by Studio) |
| `supabase_edge_runtime_Convivo` | `supabase/edge-runtime` | Edge functions (unused in v1) |
| `supabase_vector_Convivo` | `supabase/vector` | Log shipping |
@@ -34,7 +34,7 @@ All containers share the external Docker network **`supabase_network_Convivo`**
| **API (Kong)** | **54321** | 8000 | The single gateway the app proxies to. **Inside the network, Kong is on 8000** — the `54321→8000` mapping is host-only. |
| Studio | 54323 | 3000 | UI — login `postgres` / `postgres` |
| Postgres | 54322 | 5432 | Direct DB — `postgres` / `postgres` |
| SMTP (Mailpit) | 54324 | 8025 | Captures emails |
| Mailpit UI | 54324 | 8025 | Capture-only testing when custom SMTP is disabled; currently bypassed by Auth |
| Analytics | 54327 | 4000 | Logflare |
> **Gotcha:** from *inside* the shared network (e.g. the app container), reach
@@ -75,11 +75,144 @@ npx supabase status
| `[api] port` | `54321` | Kong gateway port |
| `[db] port` | `54322` | Postgres port |
| `[studio] port` | `54323` | Studio port |
| `[auth.email] enable_confirmations` | `false` | **No email is sent** — the QR+email login never emails the user |
| `[auth.email] enable_confirmations` | `false` | Signup confirmation is disabled locally; explicit magic-link requests still send email |
| `[auth] jwt_expiry` | `86400` | **24-hour login** — the session JWT lives a full day |
| `[auth] site_url` | `http://127.0.0.1:3000` | The app origin |
| `[auth] additional_redirect_urls` | Exact local attendee, speaker and Admin URLs | Allows magic links to return to the requested app route |
| `[auth.rate_limit] email_sent` | `100` | Project-wide hourly budget when using custom SMTP; not an entitlement to provider capacity |
| `[auth.email] max_frequency` | `60s` | Minimum resend interval, matching the Admin UI cooldown |
| `[auth.email] otp_expiry` | `3600` | Magic links expire after one hour and are single-use |
| `[auth.email.smtp] enabled` | `true` | Explicit local opt-in to real outbound MXroute email, not Mailpit capture |
| `[auth.email.smtp] pass` | `env(CONVIVO_SMTP_PASSWORD)` | Password loaded from a private runtime environment, never committed |
| `[db.seed] sql_paths` | `["./seed.sql"]` | Seed runs on reset |
## Magic-link configuration
### Local development
The committed [config](../../supabase/config.toml) keeps `site_url` on
`http://127.0.0.1:3000` and retains the existing HTTPS localhost entry. It adds
these exact HTTP redirect destinations for **both** `localhost` and `127.0.0.1`:
- Port 3000: the app origin, `/speaker`, and `/speaker/secret`.
- Port 3001: `/auth/callback` for [Admin magic links](../frontend/admin-app.md#magic-links).
Hosts, schemes, ports and paths must match; there are no wildcard redirects.
For an alternate dev port, explicitly allow its callback URL before testing
real email links. Mocked browser tests do not exercise the Auth allowlist.
Local Auth explicitly opts into **real outbound email** through MXroute:
`heracles.mxrouting.net:465`, SMTP user and From address `[email protected]`,
sender name `Convivo APP`. GoTrue's mail transport selects implicit TLS for
port 465 and verifies the server certificate; no insecure TLS override is used.
Mailpit remains available but does not capture these externally delivered emails.
The password is referenced only as `env(CONVIVO_SMTP_PASSWORD)`. On this machine,
it is provisioned in the git-ignored `supabase/.env`, with owner-only permissions
(`0600`). Supabase CLI **2.115.0** loads dotenv files starting in `supabase/`
and then the project root, so ordinary `npm run db:start` retains SMTP delivery
without a shell export or helper. Existing process environment variables and
higher-priority dotenv files can override this value. For another checkout,
provision the same variable through a private secret store or ignored dotenv
file before starting; do not put the password in commands, tracked files,
frontend variables, screenshots, or diagnostic output.
Apply configuration changes with a local-only, volume-preserving restart:
```bash
npx supabase stop --project-id Convivo
npx supabase start
```
Expect a brief interruption of local services. Do **not** use `--no-backup`,
`--all`, or `db:reset`: no database reset, seed, or user creation is needed.
Configuration edits alone do not reconfigure a running Auth container.
For capture-only tests, set `[auth.email.smtp] enabled = false` and restart;
then inspect Mailpit at `http://127.0.0.1:54324`. Restore `enabled = true` and
restart when deliberately returning to real delivery.
Local activation was checked on 2026-10-07: normal stop/start restored the
database from backup, Auth became healthy, and its runtime SMTP host, port,
user, sender and password matched the intended configuration. The password
comparison was performed without displaying it and with no shell export,
confirming dotenv persistence. This activation check sent **no email** and does
not prove inbox delivery. The separately authorized frontend/Auth delivery check
must use an existing eligible account, verify the received link and exact
`redirect_to`, and respect the 60-second resend interval.
### Production activation (2026-10-07)
The CLI-managed VM deployment at `/home/APPE/convivo` now has verified DNS,
TLS and public routing for `convivo.appe.at` and `admin.appe.at`. Both app
origins and the exact speaker/Admin callback routes return HTTP 200; public
Auth health returns 200. `db.appe.at` has no DNS record and is not used.
See [deployment evidence and backups](../deployment.md#production-status-2026-10-07).
Production-specific changes were made only to the remote config, retaining
other settings rather than copying the local config wholesale:
- `[auth] site_url = "https://convivo.appe.at"`.
- `[auth] external_url = "https://convivo.appe.at/auth/v1"`, verified through
the attendee app's same-origin Auth proxy.
- Exact redirect additions: `https://convivo.appe.at`,
`https://admin.appe.at`, `https://convivo.appe.at/speaker`,
`https://convivo.appe.at/speaker/secret`, and
`https://admin.appe.at/auth/callback`. The pre-existing exact
`https://127.0.0.1:3000` entry was preserved; no wildcard was added.
- `[auth] jwt_issuer` explicitly retains
`http://127.0.0.1:54321/auth/v1`. This is token issuer identity, not the
public verification link. Both issuer and signing secret matched the
pre-restart Auth runtime, preserving existing session semantics.
- Custom SMTP is enabled at `heracles.mxrouting.net:465`, using implicit TLS
with verified certificates, SMTP user/From `[email protected]`, and sender
`Convivo APP`. Runtime password equality was checked without disclosure.
- `pass = "env(CONVIVO_SMTP_PASSWORD)"` loads from the private remote
`supabase/.env` (0600). Only this approved variable was provisioned over
encrypted SSH stdin; existing dotenv variables and root environment files
were preserved. No secret or local fixture dotenv was synced.
- The hourly email budget is 100, resend interval 60 seconds, and OTP expiry
3600 seconds. The standard verification-link template was retained.
The remote config passed CLI validation, then normal CLI **2.115.0** stop/start
activated it without reset, seed, data-volume deletion, or core image changes.
Both frontends were replaced from prebuilt images; the existing sidecar was
left running. Speaker RPC privileges and material write policies passed
post-restart checks, including assigned speakers registered as `staff` and
exclusion of non-session slots.
One authorized Admin magic-link request for the existing `[email protected]` account
returned HTTP 200 with account creation disabled. This verifies API acceptance
of the SMTP-backed request, not inbox receipt or full browser sign-in.
SPF/DKIM/DMARC, received-link contents, expiry/reuse rejection, and browser
screenshots remain separate verification work. Do not send additional test
emails or create production fixtures without explicit authorization.
### Rate limits and abuse boundary
The local policy is 100 Auth emails per project per hour and a 60-second resend
interval. The committed SMTP block is enabled for explicitly requested local
real delivery. Hosted Supabase's built-in
email provider has its own restrictions (currently two emails/hour and delivery
only to authorized team addresses); changing this file does not raise those
limits. Production needs custom SMTP and an explicitly configured hourly limit
that fits both provider capacity and the expected audience.
The browser cooldown and generic confirmation are UX/privacy controls, **not**
abuse enforcement. `shouldCreateUser: false` prevents this client from creating
accounts but does not prevent direct requests to public Auth endpoints, or
emailing existing non-admin users. The admin gate and database RLS control
access, not outbound mail. Enforce Auth's server-side per-user/IP/project limits,
monitor delivery failures and quota exhaustion, and evaluate CAPTCHA or a
server-side send-email policy before public rollout. Raising the hourly budget
increases spam and quota-exhaustion exposure; do not remove the resend limit.
Account-neutral UI messages do not guarantee that the underlying Auth API is
resistant to enumeration.
Current references: [passwordless email](https://supabase.com/docs/guides/auth/auth-email-passwordless),
[redirect URLs](https://supabase.com/docs/guides/auth/redirect-urls),
[custom SMTP](https://supabase.com/docs/guides/auth/auth-smtp), and
[rate limits](https://supabase.com/docs/guides/auth/rate-limits).
## Keys
| Key | Value | Where it's used |
+46
View File
@@ -42,6 +42,52 @@ docker exec -i supabase_db_Convivo psql -U postgres < supabase/tests/rpc_tests.s
| Speaker auto-promote trigger | attendee → speaker, never overrides staff |
| Leaderboard | excludes staff |
## Speaker Portal
[speaker_portal_tests.sql](../../supabase/tests/speaker_portal_tests.sql) is an
independent fail-fast suite (`ON_ERROR_STOP`) with generated contacts/events/talks,
temporary snapshots and a single transaction ending in `ROLLBACK`. It needs the
[speaker portal migration](../../supabase/migrations/20261006175631_speaker_portal.sql)
and [staff overlap migration](../../supabase/migrations/20261007153957_speaker_portal_staff_overlap.sql)
on the **local** database. Apply without resetting existing data:
```bash
docker exec -i supabase_db_Convivo psql -U postgres -d postgres -v ON_ERROR_STOP=1 --single-transaction < supabase/migrations/20261006175631_speaker_portal.sql
docker exec -i supabase_db_Convivo psql -U postgres -d postgres -v ON_ERROR_STOP=1 --single-transaction < supabase/migrations/20261007153957_speaker_portal_staff_overlap.sql
docker exec -i supabase_db_Convivo psql -U postgres -d postgres -v ON_ERROR_STOP=1 < supabase/tests/speaker_portal_tests.sql
```
This direct migration application reloads the local API schema but does not
write CLI migration history. It is not a production deployment command. No
database reset is needed; fixture sequence state is not advanced.
The suite checks assigned speaker, non-admin staff and Admin staff access,
unassigned staff, mismatched same-event registrations, attendee assignments,
unregistered assignments, automatic service-session exclusion, active/inactive past/future
events, malformed and cross-session paths, required uploaded objects, Storage
INSERT/UPDATE/DELETE (including UPDATE WITH CHECK) and unchanged registration,
points-log, check-in and leaderboard state. Storage policy checks use the
`authenticated` database role, not a superuser that bypasses RLS. A failed
assertion exits non-zero and connection closure rolls back the transaction.
[speaker-portal.spec.ts](../../e2e/tests/speaker-portal.spec.ts) uses mocked Auth,
REST and Storage responses, without real credentials or mail delivery:
```bash
cd e2e
CONVIVO_BASE_URL=http://127.0.0.1:3000 npx playwright test tests/speaker-portal.spec.ts --project=chromium --reporter=list --output=/tmp/convivo-speaker-results
```
Start Convivo's dev server first. Coverage includes both routes, existing-users-only
link requests, URL scrubbing, callback errors/rejections, StrictMode single-use
implicit/PKCE callbacks, local logout, empty access, upload/replace/remove across
desktop/mobile, failed attachment cleanup and the normal app's check-in gate
after portal login. Mocked tests do not validate live mail delivery, deployment
redirect allowlists or real Storage behavior; the SQL suite validates database
authorization separately. See [screen contract](../frontend/screens.md#speaker-portal),
[API client](../frontend/api-client.md#speaker-portal), [RLS](./rls.md#speaker-portal-authorization)
and [RPCs](./rpcs.md#speaker-portal-rpcs).
## Files
- [`supabase/tests/rpc_tests.sql`](../../supabase/tests/rpc_tests.sql) — the test