From 1bffae977779051d66e10854bccbf55973a08b13 Mon Sep 17 00:00:00 2001 From: Jose Lago Date: Sun, 23 Aug 2026 19:18:59 +0200 Subject: [PATCH] Convivo login: staff QR asks for staff password (not email) When a staff QR is detected, the confirm step now shows a password field instead of the email field. Login uses the resolved contact's email + the entered staff password (signInWithPassword). Attendees are unchanged (QR + ticket email). Docs updated (screens.md, architecture.md). --- apps/convivo/src/screens/Login.tsx | 78 ++++++++++++++++++++++-------- docs/architecture.md | 17 ++++--- docs/frontend/screens.md | 18 +++++-- 3 files changed, 81 insertions(+), 32 deletions(-) diff --git a/apps/convivo/src/screens/Login.tsx b/apps/convivo/src/screens/Login.tsx index 7b1deb1..31b1706 100644 --- a/apps/convivo/src/screens/Login.tsx +++ b/apps/convivo/src/screens/Login.tsx @@ -13,10 +13,14 @@ export function Login() { const [qrToken, setQrToken] = useState(''); const [found, setFound] = useState(null); const [email, setEmail] = useState(''); + const [staffPassword, setStaffPassword] = useState(''); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const { toast } = useToast(); + // Staff log in with QR + their admin password; everyone else with QR + email. + const isStaff = found?.registration_type === 'staff'; + async function handleScan(text: string) { const token = text.trim(); if (!token) return; @@ -33,16 +37,24 @@ export function Login() { } async function confirm() { - if (!email.trim() || !qrToken) return; + // Staff: QR + admin password (email comes from the resolved contact). + // Attendees: QR + the ticket email (the QR token is the auth password). + const loginEmail = isStaff ? found?.email : email.trim(); + const loginPassword = isStaff ? staffPassword : qrToken; + if (!loginEmail || !loginPassword) return; setBusy(true); setError(null); try { const { data, error: err } = await supabase.auth.signInWithPassword({ - email: email.trim(), - password: qrToken, + email: loginEmail, + password: loginPassword, }); if (err) { - setError('Email and QR code do not match. Please try again.'); + setError( + isStaff + ? 'That password is incorrect. Please try again.' + : 'Email and QR code do not match. Please try again.' + ); toast('Login failed', 'err'); } else if (data.session) { toast('Welcome back! 🎉', 'ok'); @@ -94,29 +106,57 @@ export function Login() {
-
Confirm it’s you
-
- Enter the email address you used when you bought your ticket. -
- setEmail(e.target.value)} - onKeyDown={(e) => e.key === 'Enter' && confirm()} - autoComplete="off" - /> + {isStaff ? ( + <> +
Staff sign in
+
+ Enter your staff password to log in. +
+ setStaffPassword(e.target.value)} + onKeyDown={(e) => e.key === 'Enter' && confirm()} + autoComplete="off" + /> + + ) : ( + <> +
Confirm it’s you
+
+ Enter the email address you used when you bought your ticket. +
+ setEmail(e.target.value)} + onKeyDown={(e) => e.key === 'Enter' && confirm()} + autoComplete="off" + /> + + )}
{error &&
{error}
} -
- Demo: ana.silva@nubank.com · bruno.costa@acme.com + {isStaff ? ( + 'Staff: QR + your admin password' + ) : ( + <>Demo: ana.silva@nubank.com · bruno.costa@acme.com + )}
); diff --git a/docs/architecture.md b/docs/architecture.md index b574bf4..c5f8625 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -127,16 +127,17 @@ the work atomically, and the `leaderboard` table change fans out over Realtime. ## 6. Authentication model -- **Attendees & staff:** the **QR token is the Supabase Auth password**; the - **email is the identifier**. Login is a standard +- **Attendees:** the **QR token is the Supabase Auth password**; the **email is + the identifier**. Login is a standard `signInWithPassword({ email, password: qrToken })`. -- **APPE Admin / staff:** can log in with **email + a real password** - (event-independent, so it works for any event). The password is recorded in - `contacts.password`; a trigger (`trg_contact_password_sync`) **auto-syncs** it - as the bcrypt hash in `auth.users.encrypted_password`, so setting it in the +- **Staff:** log in with **QR + their admin password** (event-independent). In + the Convivo app, scanning a staff QR shows a **password** field (not the email + field); the email is taken from the resolved contact. The password is recorded + in `contacts.password`; a trigger (`trg_contact_password_sync`) **auto-syncs** + it as the bcrypt hash in `auth.users.encrypted_password`, so setting it in the Supabase Table Editor makes it work with `signInWithPassword` immediately. - Staff can also still log in with their email + QR token (their seeded Auth - password). + (Staff can also still log in with their email + QR token, their seeded 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/frontend/screens.md b/docs/frontend/screens.md index 124f65b..d4c5ab9 100644 --- a/docs/frontend/screens.md +++ b/docs/frontend/screens.md @@ -25,12 +25,20 @@ A 3-step flow: **splash → scan → confirm**. 2. **Scan** — scan (or type) your lanyard QR. Calls `lanyardLookup(qrToken)` to resolve the contact (pre-login, public). Shows the resolved name + registration type badge. -3. **Confirm** — enter the **email used to buy the ticket**, then - `signInWithPassword({ email, password: qrToken })`. On success the - `AuthContext` updates and the Shell renders the app. On mismatch, an error is - shown ("Email and QR code do not match"). +3. **Confirm** — the field depends on the resolved role: + - **Staff** (`registration_type === 'staff'`) — enter the **staff password**. + Login is `signInWithPassword({ email: , password })`. + (The email is taken from the resolved contact, so staff only type their + password.) + - **Everyone else** — enter the **email used to buy the ticket**, then + `signInWithPassword({ email, password: qrToken })` (the QR token is the auth + password). -> This is the QR + email login — no email is ever sent. See + On success the `AuthContext` updates and the Shell renders the app. On + mismatch, an error is shown ("Email and QR code do not match" for attendees, + "That password is incorrect" for staff). + +> No email is ever sent. See > [../architecture.md#6-authentication-model](../architecture.md#6-authentication-model) > and [../backend/rls.md](../backend/rls.md).