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).
This commit is contained in:
Lago committed 2026-08-23 19:18:59 +02:00
1 parent 698bf13551
commit 1bffae9777
3 files changed
+81 -32

No files matched your search

+59 -19
View File
@@ -13,10 +13,14 @@ export function Login() {
const [qrToken, setQrToken] = useState(''); const [qrToken, setQrToken] = useState('');
const [found, setFound] = useState<PublicContact | null>(null); const [found, setFound] = useState<PublicContact | null>(null);
const [email, setEmail] = useState(''); const [email, setEmail] = useState('');
const [staffPassword, setStaffPassword] = useState('');
const [busy, setBusy] = useState(false); const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const { toast } = useToast(); 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) { async function handleScan(text: string) {
const token = text.trim(); const token = text.trim();
if (!token) return; if (!token) return;
@@ -33,16 +37,24 @@ export function Login() {
} }
async function confirm() { 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); setBusy(true);
setError(null); setError(null);
try { try {
const { data, error: err } = await supabase.auth.signInWithPassword({ const { data, error: err } = await supabase.auth.signInWithPassword({
email: email.trim(), email: loginEmail,
password: qrToken, password: loginPassword,
}); });
if (err) { 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'); toast('Login failed', 'err');
} else if (data.session) { } else if (data.session) {
toast('Welcome back! 🎉', 'ok'); toast('Welcome back! 🎉', 'ok');
@@ -94,29 +106,57 @@ export function Login() {
</div> </div>
</div> </div>
<div className="card"> <div className="card">
<div className="h2" style={{ marginBottom: 6 }}>Confirm it’s you</div> {isStaff ? (
<div className="muted small" style={{ marginBottom: 12 }}> <>
Enter the email address you used when you bought your ticket. <div className="h2" style={{ marginBottom: 6 }}>Staff sign in</div>
</div> <div className="muted small" style={{ marginBottom: 12 }}>
<input Enter your staff password to log in.
className="input" </div>
type="email" <input
placeholder="[email protected]" className="input"
value={email} type="password"
onChange={(e) => setEmail(e.target.value)} placeholder="••••••••••"
onKeyDown={(e) => e.key === 'Enter' && confirm()} value={staffPassword}
autoComplete="off" onChange={(e) => setStaffPassword(e.target.value)}
/> onKeyDown={(e) => e.key === 'Enter' && confirm()}
autoComplete="off"
/>
</>
) : (
<>
<div className="h2" style={{ marginBottom: 6 }}>Confirm it’s you</div>
<div className="muted small" style={{ marginBottom: 12 }}>
Enter the email address you used when you bought your ticket.
</div>
<input
className="input"
type="email"
placeholder="[email protected]"
value={email}
onChange={(e) => setEmail(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && confirm()}
autoComplete="off"
/>
</>
)}
</div> </div>
{error && <div className="muted small" style={{ color: 'var(--red)' }}>{error}</div>} {error && <div className="muted small" style={{ color: 'var(--red)' }}>{error}</div>}
<button className="btn primary" disabled={busy || !email.trim()} onClick={confirm}> <button
className="btn primary"
disabled={busy || (isStaff ? !staffPassword : !email.trim())}
onClick={confirm}
>
{busy ? 'Checking…' : 'Confirm & enter →'} {busy ? 'Checking…' : 'Confirm & enter →'}
</button> </button>
<button className="btn ghost small" style={{ alignSelf: 'flex-start' }} onClick={() => setStep('scan')}> <button className="btn ghost small" style={{ alignSelf: 'flex-start' }} onClick={() => setStep('scan')}>
← Different lanyard ← Different lanyard
</button> </button>
<div className="muted small" style={{ textAlign: 'center', opacity: 0.6 }}> <div className="muted small" style={{ textAlign: 'center', opacity: 0.6 }}>
Demo: <b>ana.silva@nubank.com</b> · <b>bruno.costa@acme.com</b> {isStaff ? (
'Staff: QR + your admin password'
) : (
<>Demo: <b>ana.silva@nubank.com</b> · <b>bruno.costa@acme.com</b></>
)}
</div> </div>
</section> </section>
); );
+9 -8
View File
@@ -127,16 +127,17 @@ the work atomically, and the `leaderboard` table change fans out over Realtime.
## 6. Authentication model ## 6. Authentication model
- **Attendees & staff:** the **QR token is the Supabase Auth password**; the - **Attendees:** the **QR token is the Supabase Auth password**; the **email is
**email is the identifier**. Login is a standard the identifier**. Login is a standard
`signInWithPassword({ email, password: qrToken })`. `signInWithPassword({ email, password: qrToken })`.
- **APPE Admin / staff:** can log in with **email + a real password** - **Staff:** log in with **QR + their admin password** (event-independent). In
(event-independent, so it works for any event). The password is recorded in the Convivo app, scanning a staff QR shows a **password** field (not the email
`contacts.password`; a trigger (`trg_contact_password_sync`) **auto-syncs** it field); the email is taken from the resolved contact. The password is recorded
as the bcrypt hash in `auth.users.encrypted_password`, so setting it in the 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. Supabase Table Editor makes it work with `signInWithPassword` immediately.
Staff can also still log in with their email + QR token (their seeded Auth (Staff can also still log in with their email + QR token, their seeded Auth
password). password.)
- `enable_confirmations = false`, so **no email is sent** — the email is only a - `enable_confirmations = false`, so **no email is sent** — the email is only a
"confirm it's you" check against the ticket purchase. "confirm it's you" check against the ticket purchase.
- After login, the app holds a **session JWT** (in `localStorage`) that lasts - After login, the app holds a **session JWT** (in `localStorage`) that lasts
+13 -5
View File
@@ -25,12 +25,20 @@ A 3-step flow: **splash → scan → confirm**.
2. **Scan** — scan (or type) your lanyard QR. Calls `lanyardLookup(qrToken)` to 2. **Scan** — scan (or type) your lanyard QR. Calls `lanyardLookup(qrToken)` to
resolve the contact (pre-login, public). Shows the resolved name + registration resolve the contact (pre-login, public). Shows the resolved name + registration
type badge. type badge.
3. **Confirm** — enter the **email used to buy the ticket**, then 3. **Confirm** — the field depends on the resolved role:
`signInWithPassword({ email, password: qrToken })`. On success the - **Staff** (`registration_type === 'staff'`) — enter the **staff password**.
`AuthContext` updates and the Shell renders the app. On mismatch, an error is Login is `signInWithPassword({ email: <resolved contact email>, password })`.
shown ("Email and QR code do not match"). (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) > [../architecture.md#6-authentication-model](../architecture.md#6-authentication-model)
> and [../backend/rls.md](../backend/rls.md). > and [../backend/rls.md](../backend/rls.md).