diff --git a/apps/convivo/src/screens/Profile.tsx b/apps/convivo/src/screens/Profile.tsx
index 9f14c1b..2b28713 100644
--- a/apps/convivo/src/screens/Profile.tsx
+++ b/apps/convivo/src/screens/Profile.tsx
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react';
import { useAuth } from '../context/AuthContext';
import { getMyPointsLog } from '../lib/api';
+import { capWords } from '../lib/time';
import type { PointsLogRow } from '../lib/types';
import { Avatar, QrImage, Spinner } from '../components/ui';
@@ -49,7 +50,7 @@ export function Profile() {
My QR code
- {contact.qr_token ? (
-
+ {registration?.qr_token ? (
+
) : (
No QR token assigned.
)}
diff --git a/apps/convivo/src/screens/Scan.tsx b/apps/convivo/src/screens/Scan.tsx
index d7d6ffd..e11f7c8 100644
--- a/apps/convivo/src/screens/Scan.tsx
+++ b/apps/convivo/src/screens/Scan.tsx
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
import { useAuth } from '../context/AuthContext';
import { useEvent } from '../lib/useEvent';
import { checkinAttendee, createConnectionRequest, lanyardLookup } from '../lib/api';
+import { capWords } from '../lib/time';
import type { CheckinResult, PublicContact } from '../lib/types';
import { Avatar, Scanner, Sheet, Spinner } from '../components/ui';
import { useToast } from '../context/ToastContext';
@@ -74,6 +75,7 @@ export function Scan() {
if (conn.status === 'accepted') toast('You’re connected! 🤝', 'ok');
else if (conn.status === 'pending') toast('Connection request sent', 'ok');
else toast('Request already resolved');
+ window.dispatchEvent(new Event('connections-changed'));
setConnectTarget(null);
} catch (e) {
toast(e instanceof Error ? e.message : 'Could not send request', 'err');
@@ -130,7 +132,7 @@ export function Scan() {
{connectTarget.contact.full_name}
{connectTarget.contact.registration_type && (
- {connectTarget.contact.registration_type.replace('_', ' ')}
+ {capWords(connectTarget.contact.registration_type)}
)}
{connectTarget.contact.linkedin_url && (
diff --git a/apps/convivo/src/styles.css b/apps/convivo/src/styles.css
index a75da75..79a9fa3 100644
--- a/apps/convivo/src/styles.css
+++ b/apps/convivo/src/styles.css
@@ -59,7 +59,7 @@ body {
/* registration types */
.pill.reg-attendee { background: rgba(148,163,184,.14); border-color: rgba(148,163,184,.4); color: #64748b; }
.pill.reg-speaker { background: rgba(124,58,237,.12); border-color: rgba(124,58,237,.4); color: #6d28d9; }
-.pill.reg-staff { background: rgba(32,178,170,.13); border-color: rgba(32,178,170,.4); color: #0f766e; }
+.pill.reg-staff { background: rgba(220,38,38,.12); border-color: rgba(220,38,38,.4); color: #b91c1c; }
.pill.reg-sponsor { background: rgba(234,88,12,.13); border-color: rgba(234,88,12,.4); color: #c2410c; }
/* slot types */
.pill.slot-type-session { background: rgba(14,165,233,.12); border-color: rgba(14,165,233,.4); color: #0369a1; }
@@ -279,3 +279,5 @@ textarea.input { resize: none; min-height: 96px; }
@keyframes spin { to { transform: rotate(360deg); } }
.center { display: flex; align-items: center; justify-content: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
+.link { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
+.clickable { cursor: pointer; }
diff --git a/docs/architecture.md b/docs/architecture.md
index 0a836a5..31adf2c 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -95,10 +95,10 @@ flag. See [frontend/admin-app.md](./frontend/admin-app.md):
Sponsors, Schedule (slots/sessions/speakers/material/AI-evaluate), Activity,
Events, and **Interfaces** (trigger Pretix/Sessionize syncs + export the QR CSV).
- **Auth guard** — same QR + email login, but non-admin sessions are rejected.
-- **Key RPCs** — `reset_qr_token` (regenerate a lanyard token + sync the Auth
- password), `adjust_points`, `upsert_contact`, `create_registration`,
- `set_registration_type`, `evaluate_session_feedback` (AI stub), and
- `set_session_material` (see [backend/rpcs.md](./backend/rpcs.md)).
+- **Key RPCs** — `reset_registration_qr_token` (regenerate a registration's
+ lanyard token + sync the Auth password), `adjust_points`, `upsert_contact`,
+ `create_registration`, `set_registration_type`, `evaluate_session_feedback`
+ (AI stub), and `set_session_material` (see [backend/rpcs.md](./backend/rpcs.md)).
## 5. How a request flows (example: staff check-in)
@@ -182,7 +182,9 @@ Convivo/
│ ├─ migrations/
│ │ ├─ 20260822000000_init.sql # original schema (replaced by the Redesign)
│ │ ├─ 20260823000000_admin_app.sql # admin read RLS + reset_qr_token (superseded)
-│ │ └─ 20260824000000_redesign.sql # ← current: multi-event model, RPCs, RLS, materials
+│ │ ├─ 20260824000000_redesign.sql # multi-event model, RPCs, RLS, materials
+│ │ ├─ 20260825000000_interfaces.sql # external_id + sync_runs + sync RPCs
+│ │ └─ 20260826000000_registration_qr_token.sql # ← current: QR token on registration
│ └─ seed.sql # 1 event, 6 slots, 18 sessions, 14 contacts, demo state
├─ docker-compose.yml # Runs both app sidecars on the Supabase network
├─ docs/ # ← this documentation
diff --git a/docs/backend/interfaces.md b/docs/backend/interfaces.md
index 3099a9a..b8a914f 100644
--- a/docs/backend/interfaces.md
+++ b/docs/backend/interfaces.md
@@ -98,15 +98,18 @@ Input: a JSON array of
`{ email, full_name, ticket_type, qr_token?, linkedin_url?, external_id? }`.
For each item:
-- **Upsert the contact** by `email`. Keeps the existing QR token unless a new
- one is supplied; **generates a token** (`CVV-XXX-NNNN`) for new ticket holders
- (Pretix doesn't provide one) so they can log in.
-- **Ensure the auth user** exists (`_ensure_auth_user` — QR token = password).
+- **Upsert the contact** by `email` (no token on the contact).
- **Map the ticket type** to a registration type via `_map_ticket_type`
(case-insensitive substring: `speaker` / `staff` / `sponsor`, else `attendee`).
- **Auto-create a sponsor row** if the type is `sponsor` (the sponsor rule
requires a sponsor lookup).
-- **Upsert the registration** for the active event (by contact).
+- **Upsert the registration** for the active event (by contact). The **QR token
+ lives on the registration**: it keeps the existing token unless a new one is
+ supplied (so a re-sync never invalidates a lanyard), and **generates a token**
+ (`CVV-XXX-NNNN`) for new ticket holders (Pretix doesn't always provide one) so
+ they can log in.
+- **Ensure the auth user** exists and **sync the token as the Auth password**
+ (QR token = password).
Returns `{ created, updated, skipped, errors[] }`.
@@ -114,7 +117,7 @@ Returns `{ created, updated, skipped, errors[] }`.
Input: a JSON array of
`{ external_id, title, description?, room?, capacity?, date, start_time, end_time,
-speakers: [{ email, full_name, qr_token? }] }`.
+speakers: [{ email, full_name }] }`.
For each item:
- **Find or create the slot** by `(event, date, start, end)` (new slots get an
@@ -146,7 +149,7 @@ Interfaces view shows the last 8 runs.
| `attendee_name` | `contacts.full_name` |
| `ticket_type` | `registrations.type` (via `_map_ticket_type`) |
| `order_code` | `contacts.external_id` + `registrations.external_id` |
-| *(generated)* | `contacts.qr_token` (for new ticket holders) |
+| `qr_token` / *(generated)* | `registrations.qr_token` (Pretix per-ticket, or generated for new holders) |
| Sessionize field | → Convivo |
|---|---|
diff --git a/docs/backend/rpcs.md b/docs/backend/rpcs.md
index a57c563..6b33093 100644
--- a/docs/backend/rpcs.md
+++ b/docs/backend/rpcs.md
@@ -125,28 +125,41 @@ Used by the APPE Admin console to award prizes or correct mistakes. Goes through
`_award_points`, so it floors at 0, writes `points_log`, and re-syncs the
leaderboard.
-### `reset_qr_token(p_contact_email)` → `(email, qr_token)`
-**Admin-only.** Regenerates a contact's lanyard QR token.
-- Generates a fresh `CVV-XXX-NNNN` token and writes it to `contacts.qr_token`.
+### `reset_registration_qr_token(p_contact_email)` → `(email, qr_token)`
+**Admin-only.** Regenerates the lanyard QR token of a contact's **registration**
+for the active event (the token lives on the registration, not the contact).
+- Requires the contact to have a registration for the active event.
+- Generates a fresh `CVV-XXX-NNNN` token and writes it to
+ `registrations.qr_token`.
- **Re-hashes it as the Auth password** (`extensions.crypt(token,
extensions.gen_salt('bf'))` on `auth.users.encrypted_password`), so the **old
token stops working** and the contact must re-scan with the new one.
- **Deletes the contact's existing `auth.sessions`**, forcing a re-login.
- Returns the new token so the admin can print/show it as a QR code.
+> **Implementation note:** the function's output column is named `email`
+> (`returns table (email, qr_token)`), so any reference to `auth.users.email`
+> inside the body must be **qualified** (`auth.users.email`) — a bare `email`
+> is ambiguous between the output column and the table column.
+
> **Implementation note:** pgcrypto's `gen_salt` / `crypt` live in the
> `extensions` schema (not `public`), so the function — whose `search_path` is
> pinned to `public` — must qualify them as `extensions.gen_salt(...)` /
> `extensions.crypt(...)`. The function owner (`postgres`) can write
> `auth.users` and `auth.sessions`, which is what makes this possible.
-### `upsert_contact(p_email, p_full_name, p_linkedin_url, p_is_admin, p_qr_token)` → `contacts`
-**Admin-only.** Creates a contact if it doesn't exist (generating a QR token when
-none is given) or updates the existing one. Returns the contact row.
+### `upsert_contact(p_email, p_full_name, p_linkedin_url, p_is_admin)` → `contacts`
+**Admin-only.** Creates a contact if it doesn't exist or updates the existing
+one. Contacts carry **no QR token** — the token is generated when a registration
+is created. Ensures an `auth.users` row exists (with a placeholder password) so
+the contact can log in once a registration token is issued. Returns the contact
+row.
### `create_registration(p_contact_email, p_type)` → `registrations`
**Admin-only.** Creates a registration for the active event (enforces the
-sponsor-type rule).
+sponsor-type rule). **Generates a `CVV-XXX-NNNN` token** on the registration and
+**syncs it as the Auth password**, so a newly registered contact can log in
+immediately.
### `set_registration_type(p_contact_email, p_type)` → `registrations`
**Admin-only.** Changes a contact's registration type for the active event.
diff --git a/docs/backend/schema.md b/docs/backend/schema.md
index a6c72e5..699f8d8 100644
--- a/docs/backend/schema.md
+++ b/docs/backend/schema.md
@@ -44,7 +44,9 @@ erDiagram
## `contacts` — people (source of truth)
One row per person. **`email` is the primary key** (a natural key that matches
-`auth.users.email`). The `qr_token` doubles as the Supabase Auth password.
+`auth.users.email`). Contacts carry **no QR token** — the token lives on the
+registration (it is generated per event by Pretix and doubles as the Auth
+password).
| Column | Type | Notes |
|---|---|---|
@@ -54,11 +56,9 @@ One row per person. **`email` is the primary key** (a natural key that matches
| `show_email` | `boolean` | default `false` — visibility toggle |
| `show_linkedin` | `boolean` | default `false` — visibility toggle |
| `is_admin` | `boolean` | default `false` — **staff = admin (merged)**; grants check-in + APPE Admin access |
-| `qr_token` | `text` **unique** | The lanyard token; **doubles as the Auth password** |
| `external_id` | `text` | nullable — the Pretix order code (set by the sync) |
| `created_at` | `timestamptz` | |
-Index: `contacts_qr_token_idx (qr_token)` — fast lanyard lookups.
Partial unique index: `contacts_external_id_uniq (external_id) WHERE external_id IS NOT NULL`.
## `events` — a conference
@@ -96,11 +96,13 @@ Points are scoped **per event** here (one row per contact per event).
| `type` | `text` | `attendee` \| `speaker` \| `staff` \| `sponsor` (default `attendee`) |
| `checked_in` | `boolean` | default `false` |
| `points` | `integer` | `>= 0`, default 0 |
+| `qr_token` | `text` | nullable — the lanyard token; **doubles as the Auth password** (generated per event) |
| `external_id` | `text` | nullable — the Pretix order code (set by the sync) |
| `created_at` | `timestamptz` | |
**Constraint:** `unique (event_id, contact_email)` — one registration per contact
-per event. Partial unique index: `registrations_external_id_uniq (external_id) WHERE external_id IS NOT NULL`.
+per event. Partial unique indexes: `registrations_external_id_uniq (external_id) WHERE external_id IS NOT NULL`
+and `registrations_qr_token_uniq (qr_token) WHERE qr_token IS NOT NULL` (fast lanyard lookups).
## `sponsors` — a sponsor for an event
diff --git a/docs/backend/seed.md b/docs/backend/seed.md
index 59078a3..b03a90c 100644
--- a/docs/backend/seed.md
+++ b/docs/backend/seed.md
@@ -8,9 +8,9 @@ Source of truth: [`supabase/seed.sql`](../../supabase/seed.sql). The seed runs o
| Data | Count | Notes |
|---|---|---|
| `auth.users` + `auth.identities` | 13 | 12 attendees + 1 admin; **QR token = bcrypt password** |
-| `contacts` | 14 | 13 with QR tokens + 1 external keynote speaker (no token) |
+| `contacts` | 14 | 13 registrants + 1 external keynote speaker (no token — tokens live on registrations) |
| `events` | 1 | **APPE 2026**, 2026-10-23, São Paulo, Brazil, **active** |
-| `registrations` | 13 | one per contact (Elena has none); points scoped here |
+| `registrations` | 13 | one per contact (Elena has none); points + **QR token** scoped here |
| `sponsors` | 3 | Nubank (headline, paid), Acme Corp (gold, paid), Globant (community, unpaid) |
| `slots` | 6 | 23 Oct, 09:00–15:45 (see table below) |
| `sessions` | 18 | 3 per slot (Main Stage / Room A / Room B) |
@@ -62,8 +62,8 @@ Login = **QR code** (typed or scanned) + **email**. The QR token is the password
| Dr. Elena Vasquez | (external speaker) | — | elena.vasquez@keynote.com | — |
> **Dr. Elena Vasquez** is an external keynote speaker: she has a `contacts` row
-> (and speaks in `session_speakers`) but **no QR token and no auth user**, so she
-> can't log in — she only appears as a speaker on the agenda.
+> (and speaks in `session_speakers`) but **no registration, no QR token, and no
+> auth user**, so she can't log in — she only appears as a speaker on the agenda.
## Ana's demo state (so the app looks alive on first login)
diff --git a/docs/frontend/admin-app.md b/docs/frontend/admin-app.md
index ac875b6..955a6a4 100644
--- a/docs/frontend/admin-app.md
+++ b/docs/frontend/admin-app.md
@@ -14,10 +14,10 @@ It runs on **port 3001** (Vite dev) or as the `convivo-admin` Docker container
| View | Purpose |
|---|---|
| **Dashboard** | Active event card (name, dates, location, aggregates: avg feedback, #sessions, #speakers, #registrations, #checked-in) + top points + recent activity. |
-| **Contacts** | Table of all contacts (email, name, LinkedIn, visibility toggles, `is_admin`, QR token). Edit, **reset the QR token**, toggle `is_admin`, set visibility. |
-| **Registrations** | Per active event: list (contact, type, checked_in). Change type (enforces the sponsor rule), mark checked-in. |
-| **Sponsors** | List (paid only visible to attendees; admin sees all). Add/edit (type, name, email, phone, paid, amount, contact lookup). |
-| **Schedule** | Slots (with type) + sessions (with speakers 1:N, material upload, `average_feedback`, `ai_generated_feedback` + an **Evaluate** stub button). |
+| **Contacts** | Table of all contacts (email, name, LinkedIn, visibility toggles, `is_admin`). Edit, toggle `is_admin`, set visibility, adjust points. (No QR token here — it lives on the registration.) |
+| **Registrations** | Per active event: list (contact, type, **QR token**, checked_in, points). Change type (enforces the sponsor rule), mark checked-in, **view + reset the QR token** (per registration). |
+| **Sponsors** | List (paid only visible to attendees; admin sees all). Add/edit (type, name, email, phone, paid, amount, **contact search-and-pick**). |
+| **Schedule** | Slots (with type) + sessions (with speakers 1:N via a **multi-select search dropdown**, material upload with a **submitted / not submitted** state, `average_feedback`, `ai_generated_feedback` + an **Evaluate** stub button). |
| **Activity** | Tables of check-ins, connections, and feedback (per active event). |
| **Events** | Create event, set active (only one), edit dates/location. |
| **Interfaces** | Trigger **Pretix** and **Sessionize** syncs (per-source or "Sync all"), show the result counts, list recent sync runs, and **export the QR CSV** (name/email/type/qr_token for the active event). |
@@ -55,8 +55,8 @@ apps/admin/src/
│ └─ Login.tsx # QR + email login (admin-only)
└─ views/
├─ Dashboard.tsx # active event + aggregates + top points + activity
- ├─ Contacts.tsx # table + edit / QR-reset / is_admin / visibility
- ├─ Registrations.tsx# per-event list + type / checked-in
+ ├─ Contacts.tsx # table + edit / is_admin / visibility / points
+ ├─ Registrations.tsx# per-event list + type / QR token (+reset) / checked-in
├─ Sponsors.tsx # sponsor CRUD
├─ Schedule.tsx # slots + sessions + speakers + material + AI-evaluate
├─ Activity.tsx # check-ins / connections / feedback tables
@@ -76,18 +76,22 @@ key. Everything it can do is allowed by RLS:
- **Writes** — direct `insert` / `update` / `delete` on `contacts`, `events`,
`registrations`, `sponsors`, `slots`, `sessions`, and `session_speakers`
(admin-only policies).
-- **RPCs** — `reset_qr_token` (regenerate a lanyard token), `adjust_points`
- (manual, audited as `admin`), `upsert_contact`, `create_registration`,
- `set_registration_type`, `evaluate_session_feedback` (AI stub), and
- `set_session_material` (attach uploaded material). See
+- **RPCs** — `reset_registration_qr_token` (regenerate a registration's lanyard
+ token), `adjust_points` (manual, audited as `admin`), `upsert_contact`,
+ `create_registration`, `set_registration_type`, `evaluate_session_feedback`
+ (AI stub), and `set_session_material` (attach uploaded material). See
[../backend/rpcs.md](../backend/rpcs.md).
### Resetting a QR token
-`reset_qr_token(contact_email)` generates a new `CVV-XXX-NNNN` token, writes it to
-`contacts.qr_token`, **re-hashes it as the Auth password** (so the old token stops
-working), and deletes the contact's existing sessions (forcing a re-login). The UI
-shows the new token as a scannable QR code.
+The QR token lives on the **registration** (per event), not the contact. The
+**Registrations** view shows each registration's token and a **QR** button that
+opens a modal with the scannable code + a **Reset token** action. Reset calls
+`reset_registration_qr_token(contact_email)`, which generates a new
+`CVV-XXX-NNNN` token, writes it to `registrations.qr_token`, **re-hashes it as the
+Auth password** (so the old token stops working), and deletes the contact's
+existing sessions (forcing a re-login). The UI shows the new token as a scannable
+QR code.
### Adjusting points
diff --git a/docs/frontend/app-structure.md b/docs/frontend/app-structure.md
index 7981194..bc8ec38 100644
--- a/docs/frontend/app-structure.md
+++ b/docs/frontend/app-structure.md
@@ -37,8 +37,9 @@ Holds the Supabase **session**, the current **`Contact`**, the current
`refresh()`, `signOut()`.
> The contact is the app's source of truth for the current user's `is_admin`
-> (staff powers) and `qr_token`; the registration holds the user's `type` and
-> `points`. After any points-changing action, screens re-fetch.
+> (staff powers); the registration holds the user's `type`, `points`, and
+> `qr_token` (the lanyard token, per event). After any points-changing action,
+> screens re-fetch.
## ToastContext (`context/ToastContext.tsx`)
diff --git a/docs/frontend/screens.md b/docs/frontend/screens.md
index 705d2b9..5c904db 100644
--- a/docs/frontend/screens.md
+++ b/docs/frontend/screens.md
@@ -43,7 +43,10 @@ The landing screen. Shows:
- **Now card** — the session the user picked for the current slot, with a
"✓ Checked in" or "Show your QR to staff to check in" pill.
- **Next card** — the pick for the next slot.
-- **My picks today** — the user's pick per slot (tap to change → opens Agenda).
+- **My picks today** — shows only **2 rows** (the current slot's pick + the next
+ slot's pick). "tap to change" is a **hyperlink** to the Agenda.
+- **Footer type badge** — the registration-type pill is shown **only for non-
+ attendee** types (Attendee is the default and is not shown at the bottom).
- **Quick actions** — Scan & connect / Check-in, Agenda, Connections, Leaderboard.
- **No active event** — a graceful empty state ("No active event right now.
Check back soon!").
@@ -98,15 +101,24 @@ Data: `useEvent()` (for the session list) + the RPCs above.
Two tabs: **My connections** and **Requests** (with a count badge).
- **My connections** — accepted connections (the other person's name +
- registration type).
+ registration type). **Clicking a row** opens a bottom **sheet** with that
+ person's **public info + their points** (avatar, name, type pill, `⚡ N pts`,
+ LinkedIn if visible, email if `show_email`). **Other people's QR codes are
+ never shown.**
- **Requests** — incoming (`to_email = me`, pending) with **Accept / Decline**
buttons (`acceptConnection` / `rejectConnection`), and outgoing (`from_email =
- me`, pending) shown as "Sent".
+ me`, pending) shown as "Sent". The person block is also clickable (same detail
+ sheet).
- Accepting awards +5 to both (see
[../backend/rpcs.md#accept_connectionp_connection_id--connections](../backend/rpcs.md#accept_connectionp_connection_id--connections)).
-- **Live-ish:** polls every 5s while the tab is visible (`usePolling`).
+- **Red dot** — any interaction with the connection logic (accept / decline / send)
+ dispatches a `connections-changed` window event; the Shell listens and
+ **recalculates the Connect red dot immediately** (it stays while any incoming
+ request is pending and disappears once none are). It also polls every 5s as a
+ fallback (`usePolling`).
-Data: `getMyConnections()` + `getPublicContacts()` (to resolve names + types).
+Data: `getMyConnections()` + `getPublicContacts()` (names + types) +
+`getLeaderboard()` (points for the detail sheet).
## Feedback
@@ -144,8 +156,9 @@ event). The `leaderboard` table is kept in sync transactionally by the RPCs —
- **Header** — avatar, name, email, registration-type pill, a **staff** pill when
`contact.is_admin`, and a points pill.
-- **My QR code** — renders `contact.qr_token` as a scannable QR (`QrImage`).
- "Show this to staff for check-in and to peers to connect."
+- **My QR code** — renders `registration.qr_token` (the token lives on the
+ registration, per event) as a scannable QR (`QrImage`). "Show this to staff for
+ check-in and to peers to connect."
- **Points breakdown** — sums `points_log` by category
(Session check-ins / Connections / Feedback / Other) + Total.
- **Log out** — `signOut()`.
diff --git a/docs/next-steps.md b/docs/next-steps.md
index 179c869..1f3ee57 100644
--- a/docs/next-steps.md
+++ b/docs/next-steps.md
@@ -4,8 +4,10 @@ What's done, what's next, and the open decisions. The full roadmap lives in the
root [`roadmap.md`](../roadmap.md); this file is the working detail for the
current phase.
-> **Current state:** Phases 0–8 are complete and verified. The **Redesign**
-> (Phases 3–6) and the **Pretix + Sessionize interfaces** (Phases 7–8) are done.
+> **Current state:** Phases 0–8 are complete and verified, plus a round of
+> **Fixes & Refinements** (QR token moved to the registration, role-pill
+> capitalization, connection detail sheet + red-dot recalc, admin schedule
+> speaker multi-select + upload/speaker bug fixes, sponsor contact search).
> Remaining work is cross-cutting (real event clock, deployment, testing) and
> the open questions in [backend/interfaces.md](./backend/interfaces.md).
@@ -179,6 +181,61 @@ Sync the **real agenda** (slots, sessions, speakers, rooms) from
- **Auth** — the Edge Function accepts an admin JWT (verified via `is_admin()`)
or a `CRON_SECRET` header for scheduled runs.
+## Fixes & Refinements — ✅ complete
+
+A cross-cutting polish round (migration `20260826000000_registration_qr_token.sql`
++ app changes), all browser-verified.
+
+**Datamodel — QR token moves from `contacts` to `registrations`.**
+- The token is a property of the **registration** (generated per event by
+ Pretix), not the contact. `contacts.qr_token` is dropped; `registrations.qr_token`
+ is added (partial unique index `registrations_qr_token_uniq`).
+- `lanyard_lookup`, `create_connection_request`, and `checkin_attendee` now
+ resolve tokens via `registrations` + the active event.
+- `reset_qr_token(contact)` is replaced by `reset_registration_qr_token(email)`
+ (admin-only; regenerates the active-event registration's token + re-hashes the
+ Auth password + clears sessions). `upsert_contact` no longer takes a token;
+ `create_registration` generates one and syncs it as the password.
+- The Pretix sync writes the token to the **registration** (keeps the existing
+ token on re-sync so a lanyard is never invalidated).
+
+**Registration types.**
+- Type pills have **distinct colors**; **red is reserved for Staff** (both apps).
+- Roles are shown **capitalized** in both apps (Attendee / Speaker / Sponsor /
+ Staff). "Attendee" is **not shown at the bottom** of the Home screen (it's the
+ default); it *is* shown (capitalized) on Profile, Login, Scan, and Connections.
+- The **reset-token button is removed from the Contacts view** (meaningless now
+ that the token lives on the registration) and moved to the **Registrations**
+ view (per-registration QR + reset).
+
+**Sessions (APPE Admin).**
+- Slot types are shown **capitalized** (Session, Keynote, Lunch Break, …).
+- The session list shows whether material was **submitted / not submitted**.
+- Speaker selection is a **multi-select search dropdown** (search + chips),
+ replacing the checkbox list.
+- **Fixed:** editing a session no longer fails with "a session must have a
+ speaker" — `setSessionSpeakers` now **diffs** (insert the new set, then delete
+ only the removed ones) instead of delete-all-then-insert, so the
+ `session_needs_speaker` trigger (which counts the row being deleted) never
+ fires. This also **fixes the file-upload bug** (the speaker save no longer
+ aborts before the material upload runs).
+
+**APPE Admin — Sponsors.**
+- The sponsor **contact lookup is a search field** (filter + click-to-pick), not
+ a dropdown of all contacts.
+
+**Convivo App.**
+- **Other people's QR codes are hidden** — the connection detail sheet shows
+ public info + points only (no QR).
+- **Connect red dot** — any interaction with the connection logic (accept /
+ decline / send) dispatches a `connections-changed` event; the Shell recalculates
+ the dot **immediately** (stays while any incoming request is pending, clears
+ when none are). 5s polling remains as a fallback.
+- **Connect menu** — clicking any connection (connected or requested) opens a
+ sheet with that person's **public info + their points**.
+- **"My picks today"** — shows only **2 rows** (current + next slot's pick);
+ "tap to change" is a **hyperlink** to the Agenda.
+
## Cross-cutting / later
- **Real event clock** — replace the simulated `DEFAULT_NOW`
diff --git a/interfaces/mock-api/fixtures/pretix.json b/interfaces/mock-api/fixtures/pretix.json
index a420201..71a47e8 100644
--- a/interfaces/mock-api/fixtures/pretix.json
+++ b/interfaces/mock-api/fixtures/pretix.json
@@ -4,19 +4,22 @@
"order_code": "PX-NEW-001",
"attendee_name": "New Attendee One",
"attendee_email": "new.one@pretix.com",
- "ticket_type": "Regular"
+ "ticket_type": "Regular",
+ "qr_token": "CVV-PX1-1001"
},
{
"order_code": "PX-NEW-002",
"attendee_name": "New Speaker Two",
"attendee_email": "new.two@pretix.com",
- "ticket_type": "Speaker"
+ "ticket_type": "Speaker",
+ "qr_token": "CVV-PX2-1002"
},
{
"order_code": "PX-ANA-003",
"attendee_name": "Ana Silva",
"attendee_email": "ana.silva@nubank.com",
- "ticket_type": "Regular"
+ "ticket_type": "Regular",
+ "qr_token": "CVV-ANA-4821"
}
]
}
diff --git a/supabase/functions/sync-trigger/index.ts b/supabase/functions/sync-trigger/index.ts
index 29c14df..8c191d0 100644
--- a/supabase/functions/sync-trigger/index.ts
+++ b/supabase/functions/sync-trigger/index.ts
@@ -86,6 +86,9 @@ async function fetchPretixAttendees(): Promise
[]> {
full_name: a.attendee_name,
ticket_type: a.ticket_type,
external_id: a.order_code,
+ // Pretix generates a QR token per ticket; it becomes the registration's
+ // token (and the login password).
+ qr_token: a.qr_token ?? null,
}));
}
@@ -94,6 +97,7 @@ interface PretixOrder {
attendee_name: string;
attendee_email: string;
ticket_type: string;
+ qr_token?: string;
}
// ---- Sessionize: fetch + normalize -----------------------------------------
diff --git a/supabase/migrations/20260826000000_registration_qr_token.sql b/supabase/migrations/20260826000000_registration_qr_token.sql
new file mode 100644
index 0000000..65d59dd
--- /dev/null
+++ b/supabase/migrations/20260826000000_registration_qr_token.sql
@@ -0,0 +1,535 @@
+-- =============================================================================
+-- Convivo — Fixes & Refinements: QR token is a property of the REGISTRATION
+--
+-- The QR token is generated by Pretix and changes per event, so it belongs on
+-- the registration (per event), not the contact (per person). This migration:
+-- * adds `registrations.qr_token` (unique) and drops `contacts.qr_token`.
+-- * re-points every token lookup at the active event's registration:
+-- lanyard_lookup, create_connection_request, checkin_attendee.
+-- * replaces `reset_qr_token(contact)` with `reset_registration_qr_token(email)`
+-- (regenerates the active event's registration token + syncs the auth
+-- password, since the token doubles as the login password).
+-- * `upsert_contact` no longer takes/sets a token (contacts have none).
+-- * the Pretix sync writes the token to the registration (Pretix generates it
+-- per ticket); the Sessionize sync no longer writes contact tokens.
+--
+-- The auth password is still the QR token (QR + email login, no email sent).
+-- =============================================================================
+
+-- -----------------------------------------------------------------------------
+-- 1. MOVE THE COLUMN
+-- -----------------------------------------------------------------------------
+alter table public.registrations add column if not exists qr_token text;
+create unique index if not exists registrations_qr_token_uniq
+ on public.registrations (qr_token) where qr_token is not null;
+
+-- Copy each contact's token onto their active-event registration (idempotent:
+-- only fills rows that don't already have a token).
+update public.registrations r
+set qr_token = c.qr_token
+from public.contacts c
+where r.contact_email = c.email
+ and r.event_id = (select id from public.events where is_active limit 1)
+ and r.qr_token is null
+ and c.qr_token is not null;
+
+-- Drop the old column (cascades the old index).
+alter table public.contacts drop column if exists qr_token;
+
+-- -----------------------------------------------------------------------------
+-- 2. TOKEN LOOKUP: resolve a QR token to the contact + registration type for
+-- the ACTIVE event (the token now lives on the registration).
+-- -----------------------------------------------------------------------------
+create or replace function public.lanyard_lookup(p_qr_token text)
+returns table (email text, full_name text, linkedin_url text,
+ show_email boolean, registration_type text)
+language sql stable security definer set search_path = public as $$
+ select c.email,
+ c.full_name,
+ case when c.show_linkedin then c.linkedin_url else null end as linkedin_url,
+ c.show_email,
+ r.type as registration_type
+ from public.registrations r
+ join public.contacts c on c.email = r.contact_email
+ where r.qr_token = p_qr_token
+ and r.event_id = (select id from public.events where is_active limit 1);
+$$;
+
+-- -----------------------------------------------------------------------------
+-- 3. CONNECTION REQUEST: resolve the scanned token to a contact (active event).
+-- -----------------------------------------------------------------------------
+create or replace function public.create_connection_request(p_target_qr text)
+returns public.connections
+language plpgsql security definer set search_path = public as $$
+declare
+ v_email text := public.current_email();
+ v_target text;
+ v_event_id uuid;
+ v_conn public.connections;
+begin
+ if v_email is null then raise exception 'not authenticated'; end if;
+ select r.contact_email into v_target
+ from public.registrations r
+ where r.qr_token = p_target_qr
+ and r.event_id = (select id from public.events where is_active limit 1);
+ if v_target is null then raise exception 'no attendee found for that QR code'; end if;
+ if v_target = v_email then raise exception 'you cannot connect with yourself'; end if;
+ select id into v_event_id from public.events where is_active limit 1;
+ if v_event_id is null then raise exception 'no active event'; end if;
+ select * into v_conn from public.connections
+ where event_id = v_event_id
+ and ((from_email = v_email and to_email = v_target)
+ or (from_email = v_target and to_email = v_email))
+ limit 1;
+ if found then
+ return v_conn;
+ end if;
+ insert into public.connections (event_id, from_email, to_email, status)
+ values (v_event_id, v_email, v_target, 'pending')
+ returning * into v_conn;
+ return v_conn;
+end;
+$$;
+
+-- -----------------------------------------------------------------------------
+-- 4. CHECK-IN: resolve the scanned token to a contact (active event).
+-- -----------------------------------------------------------------------------
+create or replace function public.checkin_attendee(p_session_id uuid, p_attendee_qr text)
+returns table (checkin_id uuid, attendee_email text, attendee_name text,
+ points integer, already boolean)
+language plpgsql security definer set search_path = public as $$
+declare
+ v_staff text := public.current_email();
+ v_attendee text;
+ v_name text;
+ v_event_id uuid;
+ v_new_id uuid;
+ v_points integer;
+ v_already boolean := false;
+begin
+ if v_staff is null then raise exception 'not authenticated'; end if;
+ if not public.is_staff_or_admin() then raise exception 'staff or admin only'; end if;
+ select r.contact_email, c.full_name into v_attendee, v_name
+ from public.registrations r
+ join public.contacts c on c.email = r.contact_email
+ where r.qr_token = p_attendee_qr
+ and r.event_id = (select id from public.events where is_active limit 1);
+ if v_attendee is null then raise exception 'no attendee found for that QR code'; end if;
+ select event_id into v_event_id from public.sessions where id = p_session_id;
+ if v_event_id is null then raise exception 'session not found'; end if;
+ insert into public.checkins (event_id, contact_email, session_id, staff_email)
+ values (v_event_id, v_attendee, p_session_id, v_staff)
+ on conflict (event_id, contact_email, session_id) do nothing
+ returning id into v_new_id;
+ if v_new_id is null then
+ v_already := true;
+ select id into v_new_id from public.checkins
+ where event_id = v_event_id and contact_email = v_attendee and session_id = p_session_id;
+ else
+ perform public._award_points(v_event_id, v_attendee, 10, 'checkin');
+ update public.registrations set checked_in = true
+ where event_id = v_event_id and contact_email = v_attendee;
+ end if;
+ select r.points into v_points from public.registrations r
+ where r.event_id = v_event_id and r.contact_email = v_attendee;
+ return query select v_new_id, v_attendee, v_name, coalesce(v_points, 0), v_already;
+end;
+$$;
+
+-- -----------------------------------------------------------------------------
+-- 5. RESET TOKEN: now per registration (active event). Regenerates the token
+-- and re-hashes it as the auth password (the old token stops working).
+-- -----------------------------------------------------------------------------
+create or replace function public.reset_registration_qr_token(p_contact_email text)
+returns table (email text, qr_token text)
+language plpgsql security definer set search_path = public as $$
+declare
+ v_uid uuid;
+ v_token text;
+ v_salt text;
+ v_event_id uuid;
+begin
+ if auth.uid() is null then raise exception 'not authenticated'; end if;
+ if not public.is_admin() then raise exception 'admin only'; end if;
+ select id into v_event_id from public.events where is_active limit 1;
+ if v_event_id is null then raise exception 'no active event'; end if;
+ if not exists (select 1 from public.registrations
+ where event_id = v_event_id and contact_email = p_contact_email) then
+ raise exception 'registration not found';
+ end if;
+ v_token := 'CVV-' || upper(substr(md5(random()::text), 1, 3)) || '-'
+ || lpad((floor(random() * 10000))::int::text, 4, '0');
+ update public.registrations set qr_token = v_token
+ where event_id = v_event_id and contact_email = p_contact_email;
+ -- Qualify auth.users.email: the function's output column is also named
+ -- `email` (returns table (email, qr_token)), so a bare `email` is ambiguous.
+ select id into v_uid from auth.users where auth.users.email = p_contact_email;
+ if v_uid is not null then
+ v_salt := extensions.gen_salt('bf');
+ update auth.users
+ set encrypted_password = extensions.crypt(v_token, v_salt), updated_at = now()
+ where id = v_uid;
+ delete from auth.sessions where user_id = v_uid;
+ end if;
+ return query select p_contact_email, v_token;
+end;
+$$;
+
+-- Drop the old contact-scoped reset function.
+drop function if exists public.reset_qr_token(text);
+
+-- -----------------------------------------------------------------------------
+-- 6. UPSERT CONTACT: contacts no longer carry a token.
+-- -----------------------------------------------------------------------------
+create or replace function public.upsert_contact(
+ p_email text, p_full_name text, p_linkedin_url text,
+ p_is_admin boolean
+)
+returns public.contacts
+language plpgsql security definer set search_path = public as $$
+declare
+ v_uid uuid;
+ v_contact public.contacts;
+begin
+ if auth.uid() is null then raise exception 'not authenticated'; end if;
+ if not public.is_admin() then raise exception 'admin only'; end if;
+ if p_email is null or btrim(p_email) = '' then raise exception 'email is required'; end if;
+ if p_full_name is null or btrim(p_full_name) = '' then raise exception 'full_name is required'; end if;
+
+ insert into public.contacts (email, full_name, linkedin_url, is_admin)
+ values (p_email, p_full_name, p_linkedin_url, coalesce(p_is_admin, false))
+ on conflict (email) do update
+ set full_name = excluded.full_name,
+ linkedin_url = excluded.linkedin_url,
+ is_admin = excluded.is_admin
+ returning * into v_contact;
+
+ -- Ensure an auth user exists so the contact can log in once a registration
+ -- token is issued (the token doubles as the password). If no auth user yet,
+ -- create one with a placeholder password; the registration token (set via
+ -- create_registration / the sync) is what actually unlocks login.
+ select id into v_uid from auth.users where email = p_email;
+ if v_uid is null then
+ insert into auth.users (instance_id, id, aud, role, email, encrypted_password,
+ email_confirmed_at, confirmation_token, recovery_token, email_change_token_new,
+ email_change, raw_app_meta_data, raw_user_meta_data,
+ created_at, updated_at, confirmation_sent_at, last_sign_in_at)
+ values ('00000000-0000-0000-0000-000000000000', gen_random_uuid(), 'authenticated',
+ 'authenticated', p_email,
+ extensions.crypt('no-token-yet', extensions.gen_salt('bf')),
+ now(), '', '', '', '', '{"provider":"email","providers":["email"]}',
+ jsonb_build_object('full_name', p_full_name), now(), now(), now(), now())
+ returning id into v_uid;
+ insert into auth.identities (id, provider_id, identity_data, provider, user_id,
+ created_at, updated_at, last_sign_in_at)
+ values (v_uid, v_uid::text,
+ jsonb_build_object('sub', v_uid::text, 'email', p_email),
+ 'email', v_uid, now(), now(), now());
+ end if;
+
+ return v_contact;
+end;
+$$;
+
+-- -----------------------------------------------------------------------------
+-- 7. CREATE REGISTRATION: generate a token (Pretix-style) + sync the auth
+-- password, so a newly registered contact can log in immediately.
+-- -----------------------------------------------------------------------------
+create or replace function public.create_registration(p_contact_email text, p_type text)
+returns public.registrations
+language plpgsql security definer set search_path = public as $$
+declare
+ v_email text := public.current_email();
+ v_event_id uuid;
+ v_reg public.registrations;
+ v_token text;
+ v_uid uuid;
+begin
+ if v_email is null then raise exception 'not authenticated'; end if;
+ if not public.is_admin() then raise exception 'admin only'; end if;
+ if not exists (select 1 from public.contacts where email = p_contact_email) then
+ raise exception 'contact not found';
+ end if;
+ if p_type is null or p_type not in ('attendee', 'speaker', 'staff', 'sponsor') then
+ raise exception 'invalid registration type';
+ end if;
+ select id into v_event_id from public.events where is_active limit 1;
+ if v_event_id is null then raise exception 'no active event'; end if;
+ if p_type = 'sponsor' and not exists (
+ select 1 from public.sponsors where event_id = v_event_id and contact_email = p_contact_email
+ ) then
+ raise exception 'a sponsor registration requires a sponsor lookup';
+ end if;
+
+ -- Generate a token for the new registration (Pretix generates one per ticket).
+ v_token := 'CVV-' || upper(substr(md5(random()::text), 1, 3)) || '-'
+ || lpad((floor(random() * 10000))::int::text, 4, '0');
+
+ insert into public.registrations (event_id, contact_email, type, qr_token)
+ values (v_event_id, p_contact_email, p_type, v_token)
+ on conflict (event_id, contact_email) do update
+ set type = excluded.type
+ returning * into v_reg;
+
+ -- Sync the auth password to the new token (so login works right away).
+ select id into v_uid from auth.users where email = p_contact_email;
+ if v_uid is not null then
+ update auth.users
+ set encrypted_password = extensions.crypt(v_reg.qr_token, extensions.gen_salt('bf')),
+ updated_at = now()
+ where id = v_uid;
+ delete from auth.sessions where user_id = v_uid;
+ end if;
+
+ return v_reg;
+end;
+$$;
+
+-- -----------------------------------------------------------------------------
+-- 8. PRETIX SYNC: write the token to the REGISTRATION (Pretix generates it per
+-- ticket). The contact no longer stores a token.
+-- -----------------------------------------------------------------------------
+create or replace function public.sync_pretix_attendees(p_attendees jsonb)
+returns jsonb
+language plpgsql security definer set search_path = public as $$
+declare
+ v_event_id uuid;
+ v_run_id uuid;
+ v_started timestamptz := now();
+ v_item jsonb;
+ v_email text;
+ v_name text;
+ v_type text;
+ v_token text;
+ v_linkedin text;
+ v_ext text;
+ v_contact public.contacts;
+ v_reg public.registrations;
+ v_created integer := 0;
+ v_updated integer := 0;
+ v_skipped integer := 0;
+ v_errors jsonb := '[]'::jsonb;
+ v_err text;
+begin
+ if coalesce(auth.jwt() ->> 'role', '') <> 'service_role' then
+ raise exception 'service_role only';
+ end if;
+ select id into v_event_id from public.events where is_active limit 1;
+ if v_event_id is null then
+ raise exception 'no active event';
+ end if;
+ insert into public.sync_runs (source, started_at, triggered_by)
+ values ('pretix', v_started, 'service_role')
+ returning id into v_run_id;
+
+ for v_item in select * from jsonb_array_elements(coalesce(p_attendees, '[]'::jsonb))
+ loop
+ begin
+ v_email := v_item ->> 'email';
+ v_name := v_item ->> 'full_name';
+ v_type := public._map_ticket_type(v_item ->> 'ticket_type');
+ v_token := v_item ->> 'qr_token';
+ v_linkedin := v_item ->> 'linkedin_url';
+ v_ext := v_item ->> 'external_id';
+
+ if v_email is null or btrim(v_email) = '' or v_name is null or btrim(v_name) = '' then
+ v_skipped := v_skipped + 1;
+ continue;
+ end if;
+
+ -- Upsert the contact (by email). No token on the contact anymore.
+ insert into public.contacts (email, full_name, linkedin_url, is_admin, external_id)
+ values (v_email, v_name, v_linkedin, false, v_ext)
+ on conflict (email) do update
+ set full_name = excluded.full_name,
+ linkedin_url = coalesce(excluded.linkedin_url, public.contacts.linkedin_url),
+ external_id = coalesce(excluded.external_id, public.contacts.external_id)
+ returning * into v_contact;
+
+ -- A `sponsor` registration requires a sponsor lookup (business rule).
+ if v_type = 'sponsor' and not exists (
+ select 1 from public.sponsors
+ where event_id = v_event_id and contact_email = v_email
+ ) then
+ insert into public.sponsors (event_id, type, name, contact_email, paid)
+ values (v_event_id, 'community', v_name, v_email, false);
+ end if;
+
+ -- Upsert the registration for the active event (by contact). The QR token
+ -- lives here (Pretix generates it per ticket). Keep the existing token
+ -- unless a new one is supplied (so a re-sync never invalidates a lanyard).
+ select qr_token into v_token
+ from public.registrations
+ where event_id = v_event_id and contact_email = v_email;
+ v_token := coalesce(v_token, v_item ->> 'qr_token',
+ 'CVV-' || upper(substr(md5(random()::text), 1, 3)) || '-'
+ || lpad((floor(random() * 10000))::int::text, 4, '0'));
+
+ insert into public.registrations (event_id, contact_email, type, external_id, qr_token)
+ values (v_event_id, v_email, v_type, v_ext, v_token)
+ on conflict (event_id, contact_email) do update
+ set type = excluded.type,
+ external_id = coalesce(excluded.external_id, public.registrations.external_id),
+ qr_token = coalesce(excluded.qr_token, public.registrations.qr_token)
+ returning * into v_reg;
+
+ -- Ensure the auth user exists (QR token = password).
+ perform public._ensure_auth_user(v_email, v_name, v_reg.qr_token);
+
+ v_updated := v_updated + 1;
+ exception when others then
+ v_err := coalesce(v_email, '') || ': ' || sqlerrm;
+ v_errors := v_errors || to_jsonb(v_err);
+ v_skipped := v_skipped + 1;
+ end;
+ end loop;
+
+ update public.sync_runs
+ set finished_at = now(), created = v_created, updated = v_updated,
+ skipped = v_skipped, error = case when jsonb_array_length(v_errors) > 0
+ then v_errors::text else null end
+ where id = v_run_id;
+
+ return jsonb_build_object('created', v_created, 'updated', v_updated,
+ 'skipped', v_skipped, 'errors', v_errors);
+end;
+$$;
+
+-- -----------------------------------------------------------------------------
+-- 9. SESSIONIZE SYNC: speakers are upserted as contacts (no token) + links.
+-- (Speakers get a login token only if they also hold a ticket/registration.)
+-- -----------------------------------------------------------------------------
+create or replace function public.sync_sessionize_sessions(p_sessions jsonb)
+returns jsonb
+language plpgsql security definer set search_path = public as $$
+declare
+ v_event_id uuid;
+ v_run_id uuid;
+ v_started timestamptz := now();
+ v_item jsonb;
+ v_ext text;
+ v_title text;
+ v_desc text;
+ v_room text;
+ v_cap integer;
+ v_date date;
+ v_start time;
+ v_end time;
+ v_slot public.slots;
+ v_session public.sessions;
+ v_spk jsonb;
+ v_spk_email text;
+ v_spk_name text;
+ v_slots_created integer := 0;
+ v_sessions_created integer := 0;
+ v_sessions_updated integer := 0;
+ v_speakers_linked integer := 0;
+ v_errors jsonb := '[]'::jsonb;
+ v_err text;
+ v_existing boolean;
+begin
+ if coalesce(auth.jwt() ->> 'role', '') <> 'service_role' then
+ raise exception 'service_role only';
+ end if;
+ select id into v_event_id from public.events where is_active limit 1;
+ if v_event_id is null then
+ raise exception 'no active event';
+ end if;
+ insert into public.sync_runs (source, started_at, triggered_by)
+ values ('sessionize', v_started, 'service_role')
+ returning id into v_run_id;
+
+ for v_item in select * from jsonb_array_elements(coalesce(p_sessions, '[]'::jsonb))
+ loop
+ begin
+ v_ext := v_item ->> 'external_id';
+ v_title := v_item ->> 'title';
+ v_desc := v_item ->> 'description';
+ v_room := v_item ->> 'room';
+ v_cap := (v_item ->> 'capacity')::int;
+ v_date := (v_item ->> 'date')::date;
+ v_start := (v_item ->> 'start_time')::time;
+ v_end := (v_item ->> 'end_time')::time;
+
+ if v_ext is null or v_title is null or v_date is null or v_start is null or v_end is null then
+ v_errors := v_errors || to_jsonb(coalesce(v_title, '') || ': missing required field');
+ continue;
+ end if;
+
+ select * into v_slot from public.slots
+ where event_id = v_event_id and slot_date = v_date
+ and start_time = v_start and end_time = v_end
+ limit 1;
+ if not found then
+ insert into public.slots (id, event_id, type, name, slot_date, start_time, end_time)
+ values (nextval('public.slots_id_seq'), v_event_id, 'session',
+ 'Slot ' || to_char(v_start, 'HH24:MI') || '–' || to_char(v_end, 'HH24:MI'),
+ v_date, v_start, v_end)
+ returning * into v_slot;
+ v_slots_created := v_slots_created + 1;
+ end if;
+
+ select exists (select 1 from public.sessions
+ where event_id = v_event_id and external_id = v_ext) into v_existing;
+ insert into public.sessions (event_id, slot_id, title, description, room, capacity, external_id)
+ values (v_event_id, v_slot.id, v_title, v_desc, v_room, v_cap, v_ext)
+ on conflict (external_id) where external_id is not null do update
+ set slot_id = excluded.slot_id,
+ title = excluded.title,
+ description = coalesce(excluded.description, public.sessions.description),
+ room = coalesce(excluded.room, public.sessions.room),
+ capacity = coalesce(excluded.capacity, public.sessions.capacity)
+ returning * into v_session;
+ if v_existing then
+ v_sessions_updated := v_sessions_updated + 1;
+ else
+ v_sessions_created := v_sessions_created + 1;
+ end if;
+
+ for v_spk in select * from jsonb_array_elements(coalesce(v_item -> 'speakers', '[]'::jsonb))
+ loop
+ v_spk_email := v_spk ->> 'email';
+ v_spk_name := v_spk ->> 'full_name';
+ if v_spk_email is null or v_spk_name is null then
+ continue;
+ end if;
+ insert into public.contacts (email, full_name)
+ values (v_spk_email, v_spk_name)
+ on conflict (email) do update
+ set full_name = excluded.full_name;
+ insert into public.session_speakers (session_id, contact_email)
+ values (v_session.id, v_spk_email)
+ on conflict (session_id, contact_email) do nothing;
+ v_speakers_linked := v_speakers_linked + 1;
+ end loop;
+ exception when others then
+ v_err := coalesce(v_title, '') || ': ' || sqlerrm;
+ v_errors := v_errors || to_jsonb(v_err);
+ end;
+ end loop;
+
+ update public.sync_runs
+ set finished_at = now(),
+ created = v_sessions_created + v_slots_created,
+ updated = v_sessions_updated,
+ skipped = 0,
+ error = case when jsonb_array_length(v_errors) > 0 then v_errors::text else null end
+ where id = v_run_id;
+
+ return jsonb_build_object('slots_created', v_slots_created,
+ 'sessions_created', v_sessions_created, 'sessions_updated', v_sessions_updated,
+ 'speakers_linked', v_speakers_linked, 'errors', v_errors);
+end;
+$$;
+
+-- -----------------------------------------------------------------------------
+-- 10. GRANTS (new/changed function signatures)
+-- -----------------------------------------------------------------------------
+grant execute on function public.lanyard_lookup(text) to authenticated;
+grant execute on function public.create_connection_request(text) to authenticated;
+grant execute on function public.checkin_attendee(uuid, text) to authenticated;
+grant execute on function public.reset_registration_qr_token(text) to authenticated;
+grant execute on function public.upsert_contact(text, text, text, boolean) to authenticated;
+grant execute on function public.create_registration(text, text) to authenticated;
+grant execute on function public.sync_pretix_attendees(jsonb) to service_role;
+grant execute on function public.sync_sessionize_sessions(jsonb) to service_role;
diff --git a/supabase/seed.sql b/supabase/seed.sql
index 00fdd8b..042f2f9 100644
--- a/supabase/seed.sql
+++ b/supabase/seed.sql
@@ -50,23 +50,24 @@ on conflict (id) do nothing;
-- -----------------------------------------------------------------------------
-- CONTACTS (PK = email). Mirrors auth.users.
-- Staff is merged into admin: Bruno, Rita, and the APPE Admin have is_admin.
--- Dr. Elena Vasquez is an external keynote speaker (no QR token / auth user).
+-- Dr. Elena Vasquez is an external keynote speaker (no registration / auth user).
+-- NOTE: the QR token lives on the REGISTRATION (per event), not the contact.
-- -----------------------------------------------------------------------------
-insert into public.contacts (email, full_name, linkedin_url, show_email, show_linkedin, is_admin, qr_token) values
- ('ana.silva@nubank.com', 'Ana Silva', 'https://linkedin.com/in/anasilva', true, true, false, 'CVV-ANA-4821'),
- ('bruno.costa@acme.com', 'Bruno Costa', 'https://linkedin.com/in/brunocosta', false, true, true, 'CVV-BRU-1177'),
- ('rita.lopes@globant.com', 'Rita Lopes', null, false, false, true, 'CVV-RIT-9034'),
- ('tomas.ribeiro@dataprev.com','Tomás Ribeiro', null, false, false, false, 'CVV-TOM-5566'),
- ('sofia.almeida@loop.com', 'Sofia Almeida', null, false, false, false, 'CVV-SOF-2299'),
- ('marco.chen@deepmind.com', 'Marco Chen', null, false, false, false, 'CVV-MRC-7712'),
- ('julia.santos@ifood.com', 'Julia Santos', null, false, false, false, 'CVV-JUL-3345'),
- ('pedro.nunes@microsoft.com', 'Pedro Nunes', null, false, false, false, 'CVV-PED-8801'),
- ('carla.mendes@quintoessencial.com', 'Carla Mendes', null, false, false, false, 'CVV-CAR-6623'),
- ('diego.ferreira@stone.com', 'Diego Ferreira', null, false, false, false, 'CVV-DIE-4458'),
- ('marina.costa@olx.com', 'Marina Costa', null, false, false, false, 'CVV-MNA-2210'),
- ('lucas.oliveira@usp.br', 'Lucas Oliveira', null, false, false, false, 'CVV-LUC-9987'),
- ('admin@appe.at', 'APPE Admin', null, false, false, true, 'CVV-ADM-0001'),
- ('elena.vasquez@keynote.com', 'Dr. Elena Vasquez', null, false, false, false, null)
+insert into public.contacts (email, full_name, linkedin_url, show_email, show_linkedin, is_admin) values
+ ('ana.silva@nubank.com', 'Ana Silva', 'https://linkedin.com/in/anasilva', true, true, false),
+ ('bruno.costa@acme.com', 'Bruno Costa', 'https://linkedin.com/in/brunocosta', false, true, true),
+ ('rita.lopes@globant.com', 'Rita Lopes', null, false, false, true),
+ ('tomas.ribeiro@dataprev.com','Tomás Ribeiro', null, false, false, false),
+ ('sofia.almeida@loop.com', 'Sofia Almeida', null, false, false, false),
+ ('marco.chen@deepmind.com', 'Marco Chen', null, false, false, false),
+ ('julia.santos@ifood.com', 'Julia Santos', null, false, false, false),
+ ('pedro.nunes@microsoft.com', 'Pedro Nunes', null, false, false, false),
+ ('carla.mendes@quintoessencial.com', 'Carla Mendes', null, false, false, false),
+ ('diego.ferreira@stone.com', 'Diego Ferreira', null, false, false, false),
+ ('marina.costa@olx.com', 'Marina Costa', null, false, false, false),
+ ('lucas.oliveira@usp.br', 'Lucas Oliveira', null, false, false, false),
+ ('admin@appe.at', 'APPE Admin', null, false, false, true),
+ ('elena.vasquez@keynote.com', 'Dr. Elena Vasquez', null, false, false, false)
on conflict (email) do nothing;
-- -----------------------------------------------------------------------------
@@ -77,23 +78,24 @@ insert into public.events (id, name, start_date, end_date, location, is_active)
on conflict (id) do nothing;
-- -----------------------------------------------------------------------------
--- REGISTRATIONS (per event). Points scoped here.
+-- REGISTRATIONS (per event). Points scoped here. The QR token lives here
+-- (per event, generated by Pretix) and doubles as the auth password.
-- Ana is checked in (has check-ins below).
-- -----------------------------------------------------------------------------
-insert into public.registrations (event_id, contact_email, type, checked_in, points) values
- ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'ana.silva@nubank.com', 'attendee', true, 40),
- ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'bruno.costa@acme.com', 'staff', false, 140),
- ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'rita.lopes@globant.com', 'staff', false, 95),
- ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'tomas.ribeiro@dataprev.com','attendee', false, 88),
- ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'sofia.almeida@loop.com', 'attendee', false, 76),
- ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'marco.chen@deepmind.com', 'attendee', false, 70),
- ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'julia.santos@ifood.com', 'attendee', false, 64),
- ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'pedro.nunes@microsoft.com', 'attendee', false, 58),
- ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'carla.mendes@quintoessencial.com', 'attendee', false, 52),
- ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'diego.ferreira@stone.com', 'attendee', false, 35),
- ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'marina.costa@olx.com', 'attendee', false, 28),
- ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'lucas.oliveira@usp.br', 'attendee', false, 15),
- ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'admin@appe.at', 'staff', false, 0)
+insert into public.registrations (event_id, contact_email, type, checked_in, points, qr_token) values
+ ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'ana.silva@nubank.com', 'attendee', true, 40, 'CVV-ANA-4821'),
+ ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'bruno.costa@acme.com', 'staff', false, 140, 'CVV-BRU-1177'),
+ ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'rita.lopes@globant.com', 'staff', false, 95, 'CVV-RIT-9034'),
+ ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'tomas.ribeiro@dataprev.com','attendee', false, 88, 'CVV-TOM-5566'),
+ ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'sofia.almeida@loop.com', 'attendee', false, 76, 'CVV-SOF-2299'),
+ ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'marco.chen@deepmind.com', 'attendee', false, 70, 'CVV-MRC-7712'),
+ ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'julia.santos@ifood.com', 'attendee', false, 64, 'CVV-JUL-3345'),
+ ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'pedro.nunes@microsoft.com', 'attendee', false, 58, 'CVV-PED-8801'),
+ ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'carla.mendes@quintoessencial.com', 'attendee', false, 52, 'CVV-CAR-6623'),
+ ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'diego.ferreira@stone.com', 'attendee', false, 35, 'CVV-DIE-4458'),
+ ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'marina.costa@olx.com', 'attendee', false, 28, 'CVV-MNA-2210'),
+ ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'lucas.oliveira@usp.br', 'attendee', false, 15, 'CVV-LUC-9987'),
+ ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'admin@appe.at', 'staff', false, 0, 'CVV-ADM-0001')
on conflict (event_id, contact_email) do nothing;
-- -----------------------------------------------------------------------------