From 8b1130f07820b6930841cd4bf640306be6755c75 Mon Sep 17 00:00:00 2001 From: Jose Lago Date: Sun, 23 Aug 2026 14:11:26 +0200 Subject: [PATCH] Admin password login + attendee profile self-service - contacts.password: admin-only APPE Admin login password (event-independent); must match the bcrypt hash in auth.users.encrypted_password (set in Supabase). - APPE Admin login is now email + password (was QR token). - update_my_profile RPC (security definer, scoped to current_email()): attendees set their LinkedIn URL + show_email / show_linkedin toggles from the Profile. - Convivo Profile gains a 'Profile settings' card (LinkedIn + 2 toggles + Save). - Visibility enforced server-side in the public projection (linkedin nulled when show_linkedin off, email omitted when show_email off). - Seed: admin password appe-admin-2026; staff keep QR tokens as auth passwords. - Docs updated (schema, rpcs, seed, admin-app, screens, api-client, architecture, next-steps, README, docker-compose). --- README.md | 16 +++--- apps/admin/src/context/AuthContext.tsx | 7 ++- apps/admin/src/lib/types.ts | 2 + apps/admin/src/screens/Login.tsx | 19 ++++--- apps/convivo/src/components/ui.tsx | 21 +++++++ apps/convivo/src/lib/api.ts | 13 +++++ apps/convivo/src/screens/Profile.tsx | 55 ++++++++++++++++++- apps/convivo/src/styles.css | 14 +++++ docker-compose.yml | 2 +- docs/architecture.md | 10 +++- docs/backend/rpcs.md | 14 +++++ docs/backend/schema.md | 1 + docs/backend/seed.md | 24 +++++--- docs/frontend/admin-app.md | 13 +++-- docs/frontend/api-client.md | 1 + docs/frontend/screens.md | 10 +++- docs/next-steps.md | 39 ++++++++++++- .../20260827000000_admin_password_profile.sql | 53 ++++++++++++++++++ supabase/seed.sql | 35 ++++++------ 19 files changed, 290 insertions(+), 59 deletions(-) create mode 100644 supabase/migrations/20260827000000_admin_password_profile.sql diff --git a/README.md b/README.md index 9d8456b..732e8b0 100644 --- a/README.md +++ b/README.md @@ -280,14 +280,16 @@ Open **http://localhost:3000** (attendee) and **http://localhost:3001** (admin). ## 12. Demo accounts -Login = **QR code** (typed or scanned) + **email**. The QR token is the password. +**Attendees & staff** log in with **QR code** (typed or scanned) + **email** — the +QR token is the password. The **APPE Admin** logs in with **email + password** +(event-independent). -| Person | Role | QR code | Email | +| Person | Role | Login | Email | |---|---|---|---| -| **Ana Silva** | attendee | `CVV-ANA-4821` | ana.silva@nubank.com | -| **Bruno Costa** | staff | `CVV-BRU-1177` | bruno.costa@acme.com | -| **Rita Lopes** | staff | `CVV-RIT-9034` | rita.lopes@globant.com | -| **APPE Admin** | admin | `CVV-ADM-0001` | admin@appe.at | +| **Ana Silva** | attendee | QR `CVV-ANA-4821` | ana.silva@nubank.com | +| **Bruno Costa** | staff | QR `CVV-BRU-1177` | bruno.costa@acme.com | +| **Rita Lopes** | staff | QR `CVV-RIT-9034` | rita.lopes@globant.com | +| **APPE Admin** | admin | **password** `appe-admin-2026` | admin@appe.at | | Tomás Ribeiro | attendee | `CVV-TOM-5566` | tomas.ribeiro@dataprev.com | | Sofia Almeida | attendee | `CVV-SOF-2299` | sofia.almeida@loop.com | | Marco Chen | attendee | `CVV-MRC-7712` | marco.chen@deepmind.com | @@ -303,7 +305,7 @@ Login = **QR code** (typed or scanned) + **email**. The QR token is the password 2. Scan **Marco** (`CVV-MRC-7712`) → send a connection request. 3. Log in as **Bruno** (staff) → the Scan tab becomes **Check-in** → pick a session → scan **Carla** (`CVV-CAR-6623`) → she gets +10. 4. Watch the **Leaderboard** update live. -5. Open the **APPE Admin** console on **:3001** → log in as **APPE Admin** (`CVV-ADM-0001` / admin@appe.at) → see the Dashboard, reset a contact's QR, adjust points, and edit the schedule. +5. Open the **APPE Admin** console on **:3001** → log in as **APPE Admin** (`admin@appe.at` / password `appe-admin-2026`) → see the Dashboard, reset a contact's QR, adjust points, and edit the schedule. ## 13. Roadmap diff --git a/apps/admin/src/context/AuthContext.tsx b/apps/admin/src/context/AuthContext.tsx index cdcc0e7..e77a8f3 100644 --- a/apps/admin/src/context/AuthContext.tsx +++ b/apps/admin/src/context/AuthContext.tsx @@ -5,7 +5,8 @@ import type { Contact } from '../lib/types'; interface AuthState { contact: Contact | null; loading: boolean; - signIn: (email: string, qrToken: string) => Promise; + /** Sign in with the admin's email + password (event-independent). */ + signIn: (email: string, password: string) => Promise; signOut: () => Promise; } @@ -72,10 +73,10 @@ export function AuthProvider({ children }: { children: ReactNode }) { }; }, []); - async function signIn(email: string, qrToken: string) { + async function signIn(email: string, password: string) { const { data, error } = await supabase.auth.signInWithPassword({ email, - password: qrToken, + password, }); if (error) throw new Error(error.message); diff --git a/apps/admin/src/lib/types.ts b/apps/admin/src/lib/types.ts index 70ade4f..29eb30c 100644 --- a/apps/admin/src/lib/types.ts +++ b/apps/admin/src/lib/types.ts @@ -19,6 +19,8 @@ export interface Contact { show_email: boolean; show_linkedin: boolean; is_admin: boolean; + /** Admin-only: the APPE Admin login password (event-independent). */ + password: string | null; created_at: string; } diff --git a/apps/admin/src/screens/Login.tsx b/apps/admin/src/screens/Login.tsx index 4e386d5..8488f25 100644 --- a/apps/admin/src/screens/Login.tsx +++ b/apps/admin/src/screens/Login.tsx @@ -6,17 +6,17 @@ export function Login() { const { signIn } = useAuth(); const { push } = useToast(); const [email, setEmail] = useState(''); - const [token, setToken] = useState(''); + const [password, setPassword] = useState(''); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); async function onSubmit(e: FormEvent) { e.preventDefault(); - if (!email.trim() || !token.trim()) return; + if (!email.trim() || !password.trim()) return; setBusy(true); setError(null); try { - await signIn(email.trim(), token.trim().toUpperCase()); + await signIn(email.trim(), password); push('success', 'Welcome back'); } catch (err) { const msg = err instanceof Error ? err.message : 'Sign in failed'; @@ -34,7 +34,7 @@ export function Login() {
APPE

APPE Admin

-

Sign in with your admin QR token and email.

+

Sign in with your admin email and password.

@@ -51,12 +51,13 @@ export function Login() { />
- + setToken(e.target.value)} + className="input" + type="password" + placeholder="••••••••••" + value={password} + onChange={(e) => setPassword(e.target.value)} autoComplete="current-password" required /> diff --git a/apps/convivo/src/components/ui.tsx b/apps/convivo/src/components/ui.tsx index 1749a17..aec5fc0 100644 --- a/apps/convivo/src/components/ui.tsx +++ b/apps/convivo/src/components/ui.tsx @@ -48,6 +48,27 @@ export function Sheet({ open, onClose, children }: { open: boolean; onClose: () ); } +/** A small on/off switch with a label. */ +export function Toggle({ + checked, + onChange, + label, +}: { + checked: boolean; + onChange: (v: boolean) => void; + label: string; +}) { + return ( + + ); +} + /** Render a string (e.g. a QR token) as a scannable QR code. */ export function QrImage({ value, size = 180 }: { value: string; size?: number }) { return ( diff --git a/apps/convivo/src/lib/api.ts b/apps/convivo/src/lib/api.ts index cd18cb3..2e1cc06 100644 --- a/apps/convivo/src/lib/api.ts +++ b/apps/convivo/src/lib/api.ts @@ -93,6 +93,19 @@ export async function getMyRegistration(email: string): Promise { + return rpc('update_my_profile', { + p_linkedin_url: input.linkedin_url, + p_show_email: input.show_email, + p_show_linkedin: input.show_linkedin, + }); +} + export async function getActiveEvent(): Promise { const { data, error } = await supabase.from('events').select('*').eq('is_active', true).maybeSingle(); if (error) throw new ApiError(error.message); diff --git a/apps/convivo/src/screens/Profile.tsx b/apps/convivo/src/screens/Profile.tsx index 2b28713..8eedb0a 100644 --- a/apps/convivo/src/screens/Profile.tsx +++ b/apps/convivo/src/screens/Profile.tsx @@ -1,9 +1,10 @@ import { useEffect, useState } from 'react'; import { useAuth } from '../context/AuthContext'; -import { getMyPointsLog } from '../lib/api'; +import { getMyPointsLog, updateMyProfile } from '../lib/api'; import { capWords } from '../lib/time'; import type { PointsLogRow } from '../lib/types'; -import { Avatar, QrImage, Spinner } from '../components/ui'; +import { Avatar, QrImage, Spinner, Toggle } from '../components/ui'; +import { useToast } from '../context/ToastContext'; const CATEGORY_LABEL: Record = { checkin: 'Session check-ins', @@ -13,10 +14,17 @@ const CATEGORY_LABEL: Record = { }; export function Profile() { - const { contact, registration, signOut } = useAuth(); + const { contact, registration, signOut, refresh } = useAuth(); + const { toast } = useToast(); const [log, setLog] = useState([]); const [loading, setLoading] = useState(true); + // Profile self-service (LinkedIn + visibility). + const [linkedin, setLinkedin] = useState(contact?.linkedin_url ?? ''); + const [showEmail, setShowEmail] = useState(contact?.show_email ?? false); + const [showLinkedin, setShowLinkedin] = useState(contact?.show_linkedin ?? false); + const [saving, setSaving] = useState(false); + const email = contact?.email ?? ''; useEffect(() => { @@ -42,6 +50,23 @@ export function Profile() { const totals: Record = {}; for (const l of log) totals[l.category] = (totals[l.category] ?? 0) + l.delta; + async function saveProfile() { + setSaving(true); + try { + await updateMyProfile({ + linkedin_url: linkedin.trim() || null, + show_email: showEmail, + show_linkedin: showLinkedin, + }); + await refresh(); + toast('Profile updated', 'ok'); + } catch (e) { + toast(e instanceof Error ? e.message : 'Could not save profile', 'err'); + } finally { + setSaving(false); + } + } + return (
Profile
@@ -68,6 +93,30 @@ export function Profile() {
+
+
Profile settings
+
+ Choose what other attendees can see on your profile. +
+
+
LinkedIn
+ setLinkedin(e.target.value)} + /> +
+
+ + +
+ +
+
Points breakdown
{loading ? ( diff --git a/apps/convivo/src/styles.css b/apps/convivo/src/styles.css index 79a9fa3..e3c435c 100644 --- a/apps/convivo/src/styles.css +++ b/apps/convivo/src/styles.css @@ -88,6 +88,20 @@ body { .input:focus { border-color: var(--accent); } textarea.input { resize: none; min-height: 96px; } .divider { height: 1px; background: var(--line); margin: 4px 0; } +/* toggle switch */ +.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; } +.toggle input { position: absolute; opacity: 0; width: 0; height: 0; } +.toggle .track { + width: 42px; height: 24px; border-radius: 999px; background: var(--line); + position: relative; transition: background .15s; flex-shrink: 0; +} +.toggle .knob { + position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; + background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; +} +.toggle input:checked + .track { background: var(--accent); } +.toggle input:checked + .track .knob { transform: translateX(18px); } +.toggle-lbl { font-size: 14px; font-weight: 600; } /* ---------- Tab bar ---------- */ .tabbar { diff --git a/docker-compose.yml b/docker-compose.yml index 3de628e..3337e5e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,7 +20,7 @@ # - http://localhost:3000 (attendee app) — log in with a demo QR code # (e.g. CVV-ANA-4821 / ana.silva@nubank.com) # - http://localhost:3001 (admin app) — log in as admin -# (CVV-ADM-0001 / admin@appe.at) +# (admin@appe.at / password appe-admin-2026) name: convivo diff --git a/docs/architecture.md b/docs/architecture.md index 31adf2c..6bc81d9 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -127,8 +127,14 @@ the work atomically, and the `leaderboard` table change fans out over Realtime. ## 6. Authentication model -- The **QR token is the Supabase Auth password**; the **email is the identifier**. - Login is a standard `signInWithPassword({ email, password: qrToken })`. +- **Attendees & staff:** the **QR token is the Supabase Auth password**; the + **email is the identifier**. Login is a standard + `signInWithPassword({ email, password: qrToken })`. +- **APPE Admin:** logs in with **email + a real password** (event-independent, so + it works for any event). The password is recorded in `contacts.password` and + must match the bcrypt hash in `auth.users.encrypted_password`. It is set + directly in Supabase (no self-service UI). Staff can also open the admin app + with their email + QR token, since that is their Auth password. - `enable_confirmations = false`, so **no email is sent** — the email is only a "confirm it's you" check against the ticket purchase. - After login, the app holds a **session JWT** (in `localStorage`) that lasts diff --git a/docs/backend/rpcs.md b/docs/backend/rpcs.md index 6b33093..5b3404f 100644 --- a/docs/backend/rpcs.md +++ b/docs/backend/rpcs.md @@ -175,6 +175,20 @@ 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. +### `update_my_profile(p_linkedin_url, p_show_email, p_show_linkedin)` → `contacts` +**Self-service (any authenticated attendee).** Lets a contact edit their own +profile from the Convivo app: the LinkedIn URL and the two visibility toggles +(`show_email` / `show_linkedin`). +- Scoped to `current_email()` — a user can only ever update **their own** row. +- `linkedin_url` is trimmed; an empty/blank value is stored as `NULL`. +- The toggles default to `false` when `NULL` is passed. +- **Why an RPC?** The `contacts` RLS `UPDATE` policy is **admin-only** + (`contacts_admin_update`), so an attendee cannot update their own row directly + through PostgREST. This `security definer` function (owner `postgres`) bypasses + that, but is deliberately limited to the three self-service columns — it cannot + touch `is_admin`, `password`, `external_id`, etc. +- Returns the updated contact row. + ## Interface sync RPCs (service-role-only) Two additional `security definer` RPCs import external data. They are **not** diff --git a/docs/backend/schema.md b/docs/backend/schema.md index 699f8d8..9b19858 100644 --- a/docs/backend/schema.md +++ b/docs/backend/schema.md @@ -56,6 +56,7 @@ password). | `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 | +| `password` | `text` | nullable — **admin-only**: the APPE Admin login password (event-independent). To work it must match the bcrypt hash in `auth.users.encrypted_password`. Set directly in Supabase (no self-service UI) | | `external_id` | `text` | nullable — the Pretix order code (set by the sync) | | `created_at` | `timestamptz` | | diff --git a/docs/backend/seed.md b/docs/backend/seed.md index b03a90c..115ad4d 100644 --- a/docs/backend/seed.md +++ b/docs/backend/seed.md @@ -7,7 +7,7 @@ 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** | +| `auth.users` + `auth.identities` | 13 | 12 attendees + 1 admin; **QR token = bcrypt password** (attendees/staff) — the admin uses a real **password** instead | | `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 + **QR token** scoped here | @@ -42,14 +42,18 @@ Source of truth: [`supabase/seed.sql`](../../supabase/seed.sql). The seed runs o ## Demo accounts -Login = **QR code** (typed or scanned) + **email**. The QR token is the password. +**Attendees & staff** log in with **QR code** (typed or scanned) + **email** — +the QR token is the Auth password. The **APPE Admin** is different: it logs in +with **email + password** (event-independent, so it works for any event). The +admin's password is stored in `contacts.password` **and** as the bcrypt hash in +`auth.users.encrypted_password` (they must match). Set it directly in Supabase. -| Person | Type | QR code | Email | Start pts | +| Person | Type | Login | Email | Start pts | |---|---|---|---|---| -| **Ana Silva** | attendee | `CVV-ANA-4821` | ana.silva@nubank.com | 40 | -| **Bruno Costa** | staff (admin) | `CVV-BRU-1177` | bruno.costa@acme.com | 140 | -| **Rita Lopes** | staff (admin) | `CVV-RIT-9034` | rita.lopes@globant.com | 95 | -| **APPE Admin** | staff (admin) | `CVV-ADM-0001` | admin@appe.at | 0 | +| **Ana Silva** | attendee | QR `CVV-ANA-4821` | ana.silva@nubank.com | 40 | +| **Bruno Costa** | staff (admin) | QR `CVV-BRU-1177` | bruno.costa@acme.com | 140 | +| **Rita Lopes** | staff (admin) | QR `CVV-RIT-9034` | rita.lopes@globant.com | 95 | +| **APPE Admin** | staff (admin) | **password** `appe-admin-2026` | admin@appe.at | 0 | | Tomás Ribeiro | attendee | `CVV-TOM-5566` | tomas.ribeiro@dataprev.com | 88 | | Sofia Almeida | attendee | `CVV-SOF-2299` | sofia.almeida@loop.com | 76 | | Marco Chen | attendee | `CVV-MRC-7712` | marco.chen@deepmind.com | 70 | @@ -98,5 +102,7 @@ Ana (`ana.silva@nubank.com`) is seeded with a coherent 40-point history: 3. Log in as **Bruno** (staff) → the Scan tab becomes **Check-in** → pick a session → scan **Carla** (`CVV-CAR-6623`) → she gets +10. 4. Watch the **Leaderboard** update live (Realtime). -5. Log in as **APPE Admin** (`CVV-ADM-0001` / `admin@appe.at`) in the admin app - → Dashboard, Contacts, Registrations, Sponsors, Schedule, Activity, Events. +5. Log in as **APPE Admin** (`admin@appe.at` / password `appe-admin-2026`) in the + admin app → Dashboard, Contacts, Registrations, Sponsors, Schedule, Activity, + Events. (Staff Bruno/Rita can also open the admin app with their email + QR + token, since that is their Auth password.) diff --git a/docs/frontend/admin-app.md b/docs/frontend/admin-app.md index 955a6a4..4b23bfb 100644 --- a/docs/frontend/admin-app.md +++ b/docs/frontend/admin-app.md @@ -24,16 +24,19 @@ It runs on **port 3001** (Vite dev) or as the `convivo-admin` Docker container ## Auth guard -Login is the same QR + email flow as the attendee app -(`signInWithPassword({ email, password: qrToken })`), but `AuthContext` checks the -contact's `is_admin` flag after signing in: +Login is **email + password** (`signInWithPassword({ email, password })`), but +`AuthContext` checks the contact's `is_admin` flag after signing in: - If `is_admin === true` → the session is accepted and the console is shown. - Otherwise → the app calls `signOut()` and shows **"This account is not an admin."** The same check runs on session restore (page reload) and on every `onAuthStateChange`, so a non-admin can never see the console. -The demo admin is `CVV-ADM-0001` / `admin@appe.at`. +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 demo admin is +`admin@appe.at` / password `appe-admin-2026`. Staff (Bruno/Rita) can also open the +admin app using their email + QR token, since that is their Auth password. ## Source layout @@ -52,7 +55,7 @@ apps/admin/src/ ├─ components/ │ └─ ui.tsx # Avatar, Spinner, Empty, Modal, QrImage, TypeBadge, Toggle ├─ screens/ -│ └─ Login.tsx # QR + email login (admin-only) +│ └─ Login.tsx # email + password login (admin-only) └─ views/ ├─ Dashboard.tsx # active event + aggregates + top points + activity ├─ Contacts.tsx # table + edit / is_admin / visibility / points diff --git a/docs/frontend/api-client.md b/docs/frontend/api-client.md index f1770d7..4b4a4b1 100644 --- a/docs/frontend/api-client.md +++ b/docs/frontend/api-client.md @@ -54,6 +54,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` | +| `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) diff --git a/docs/frontend/screens.md b/docs/frontend/screens.md index 5c904db..6737915 100644 --- a/docs/frontend/screens.md +++ b/docs/frontend/screens.md @@ -159,8 +159,16 @@ event). The `leaderboard` table is kept in sync transactionally by the RPCs — - **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." +- **Profile settings** — self-service card: a **LinkedIn** URL input plus two + **visibility toggles** ("Show my email" / "Show my LinkedIn") and a **Save + profile** button. Saving calls `update_my_profile` (the security-definer RPC, + since the `contacts` UPDATE policy is admin-only), then `refresh()` to reload + the contact. The toggles control what other attendees see — the public + projection (`lanyard_lookup` / `get_public_contacts`) nulls `linkedin_url` when + `show_linkedin` is off and omits the email when `show_email` is off. - **Points breakdown** — sums `points_log` by category (Session check-ins / Connections / Feedback / Other) + Total. - **Log out** — `signOut()`. -Data: `useAuth()` (contact + registration) + `getMyPointsLog(email)`. +Data: `useAuth()` (contact + registration + `refresh`) + `getMyPointsLog(email)` ++ `updateMyProfile(...)`. diff --git a/docs/next-steps.md b/docs/next-steps.md index 1f3ee57..927d7e6 100644 --- a/docs/next-steps.md +++ b/docs/next-steps.md @@ -4,10 +4,12 @@ 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, plus a round of -> **Fixes & Refinements** (QR token moved to the registration, role-pill +> **Current state:** Phases 0–8 are complete and verified, plus two polish +> rounds: **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). +> speaker multi-select + upload/speaker bug fixes, sponsor contact search) and +> **Admin password + profile self-service** (admin logs in with email + password; +> attendees set LinkedIn + visibility on their Profile). > Remaining work is cross-cutting (real event clock, deployment, testing) and > the open questions in [backend/interfaces.md](./backend/interfaces.md). @@ -236,6 +238,37 @@ A cross-cutting polish round (migration `20260826000000_registration_qr_token.sq - **"My picks today"** — shows only **2 rows** (current + next slot's pick); "tap to change" is a **hyperlink** to the Agenda. +## Admin password + profile self-service — ✅ complete + +Migration `20260827000000_admin_password_profile.sql` + app changes, all +browser-verified. + +**APPE Admin login = email + password (event-independent).** +- `contacts.password` (admin-only) records the APPE Admin login password. To + work it must match the bcrypt hash in `auth.users.encrypted_password` — set + directly in Supabase (no self-service UI/procedure). +- The admin app's Login screen is now **Email + Password** (was QR token). + `AuthContext.signIn(email, password)` still calls `signInWithPassword` + the + `is_admin` guard. +- **Design decision:** Supabase Auth has one password per user. The dedicated + admin uses a real password (works for any event). Staff (Bruno/Rita) keep + their QR tokens as their Auth password — they can still log into the attendee + app, and can also open the admin app with email + QR token. +- Seed: the admin's password is `appe-admin-2026` (in both `contacts.password` + and `auth.users.encrypted_password`); all other contacts have `password = NULL`. + +**Convivo App — Profile self-service.** +- New **Profile settings** card: a **LinkedIn** URL input + two **visibility + toggles** ("Show my email" / "Show my LinkedIn") + **Save profile**. +- Saving calls the new `update_my_profile(p_linkedin_url, p_show_email, + p_show_linkedin)` RPC (security-definer, scoped to `current_email()`, limited + to those 3 columns) — needed because the `contacts` UPDATE policy is + admin-only, so an attendee can't update their own row via PostgREST. +- Visibility is enforced **server-side**: the public projection + (`lanyard_lookup` / `get_public_contacts`) nulls `linkedin_url` when + `show_linkedin` is off and omits the email when `show_email` is off, so the + toggles actually control what other attendees see. + ## Cross-cutting / later - **Real event clock** — replace the simulated `DEFAULT_NOW` diff --git a/supabase/migrations/20260827000000_admin_password_profile.sql b/supabase/migrations/20260827000000_admin_password_profile.sql new file mode 100644 index 0000000..9a2899c --- /dev/null +++ b/supabase/migrations/20260827000000_admin_password_profile.sql @@ -0,0 +1,53 @@ +-- ============================================================================= +-- Convivo — Admin password + attendee profile self-service +-- +-- 1. `contacts.password` — an admin-only property: the admin's APPE Admin login +-- password. It is independent of the per-event QR token, so an admin can log +-- into APPE Admin at any time, regardless of the active event. +-- +-- NOTE: Supabase Auth has a single password per user +-- (`auth.users.encrypted_password`). For `contacts.password` to work as the +-- APPE Admin login, the matching `auth.users.encrypted_password` must be its +-- bcrypt hash. Admins set both directly in Supabase (no self-service UI in +-- v1). The seed gives the dedicated admin a demo password in both places. +-- +-- 2. `update_my_profile` — lets a signed-in attendee update their OWN contact +-- row: LinkedIn URL + the two visibility toggles (show_email / show_linkedin). +-- Scoped to the caller (`current_email()`); only those three columns are +-- writable, so it can't touch `is_admin`, `password`, etc. +-- ============================================================================= + +-- ----------------------------------------------------------------------------- +-- 1. ADMIN PASSWORD (admin-only property on the contact) +-- ----------------------------------------------------------------------------- +alter table public.contacts add column if not exists password text; +comment on column public.contacts.password is + 'Admin-only: the APPE Admin login password (event-independent). To work it must ' + 'match the bcrypt hash in auth.users.encrypted_password. Set directly in Supabase.'; + +-- ----------------------------------------------------------------------------- +-- 2. UPDATE MY PROFILE (attendee self-service: LinkedIn + visibility) +-- ----------------------------------------------------------------------------- +create or replace function public.update_my_profile( + p_linkedin_url text, p_show_email boolean, p_show_linkedin boolean +) +returns public.contacts +language plpgsql security definer set search_path = public as $$ +declare + v_email text := public.current_email(); + v_contact public.contacts; +begin + if v_email is null then raise exception 'not authenticated'; end if; + update public.contacts + set linkedin_url = case when p_linkedin_url is null or btrim(p_linkedin_url) = '' + then null else btrim(p_linkedin_url) end, + show_email = coalesce(p_show_email, false), + show_linkedin = coalesce(p_show_linkedin, false) + where email = v_email + returning * into v_contact; + if not found then raise exception 'contact not found'; end if; + return v_contact; +end; +$$; + +grant execute on function public.update_my_profile(text, boolean, boolean) to authenticated; diff --git a/supabase/seed.sql b/supabase/seed.sql index 042f2f9..3a1b38b 100644 --- a/supabase/seed.sql +++ b/supabase/seed.sql @@ -28,7 +28,7 @@ insert into auth.users (instance_id, id, aud, role, email, encrypted_password, e ('00000000-0000-0000-0000-000000000000', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'authenticated', 'authenticated', 'diego.ferreira@stone.com', crypt('CVV-DIE-4458', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Diego Ferreira"}', now(), now(), now(), now()), ('00000000-0000-0000-0000-000000000000', 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'authenticated', 'authenticated', 'marina.costa@olx.com', crypt('CVV-MNA-2210', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Marina Costa"}', now(), now(), now(), now()), ('00000000-0000-0000-0000-000000000000', 'cccccccc-cccc-cccc-cccc-cccccccccccc', 'authenticated', 'authenticated', 'lucas.oliveira@usp.br', crypt('CVV-LUC-9987', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Lucas Oliveira"}', now(), now(), now(), now()), - ('00000000-0000-0000-0000-000000000000', 'dddddddd-dddd-dddd-dddd-dddddddddddd', 'authenticated', 'authenticated', 'admin@appe.at', crypt('CVV-ADM-0001', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"APPE Admin"}', now(), now(), now(), now()) + ('00000000-0000-0000-0000-000000000000', 'dddddddd-dddd-dddd-dddd-dddddddddddd', 'authenticated', 'authenticated', 'admin@appe.at', crypt('appe-admin-2026', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"APPE Admin"}', now(), now(), now(), now()) on conflict (id) do nothing; insert into auth.identities (id, provider_id, identity_data, provider, user_id, created_at, updated_at, last_sign_in_at) values @@ -53,21 +53,24 @@ on conflict (id) do nothing; -- 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) 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) +-- `password` is the admin-only APPE Admin login password (event-independent). +-- Only the dedicated admin is seeded with one (demo value; override in Supabase). +-- Staff (Bruno/Rita) keep their QR token as the auth password for the attendee app. +insert into public.contacts (email, full_name, linkedin_url, show_email, show_linkedin, is_admin, password) values + ('ana.silva@nubank.com', 'Ana Silva', 'https://linkedin.com/in/anasilva', true, true, false, null), + ('bruno.costa@acme.com', 'Bruno Costa', 'https://linkedin.com/in/brunocosta', false, true, true, null), + ('rita.lopes@globant.com', 'Rita Lopes', null, false, false, true, null), + ('tomas.ribeiro@dataprev.com','Tomás Ribeiro', null, false, false, false, null), + ('sofia.almeida@loop.com', 'Sofia Almeida', null, false, false, false, null), + ('marco.chen@deepmind.com', 'Marco Chen', null, false, false, false, null), + ('julia.santos@ifood.com', 'Julia Santos', null, false, false, false, null), + ('pedro.nunes@microsoft.com', 'Pedro Nunes', null, false, false, false, null), + ('carla.mendes@quintoessencial.com', 'Carla Mendes', null, false, false, false, null), + ('diego.ferreira@stone.com', 'Diego Ferreira', null, false, false, false, null), + ('marina.costa@olx.com', 'Marina Costa', null, false, false, false, null), + ('lucas.oliveira@usp.br', 'Lucas Oliveira', null, false, false, false, null), + ('admin@appe.at', 'APPE Admin', null, false, false, true, 'appe-admin-2026'), + ('elena.vasquez@keynote.com', 'Dr. Elena Vasquez', null, false, false, false, null) on conflict (email) do nothing; -- -----------------------------------------------------------------------------