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). Co-authored-by: Stephan Charles <[email protected]> Co-authored-by: Amelia Hernandez <[email protected]> Co-authored-by: Markus Franz <[email protected]> Co-authored-by: Sabrina Hota <[email protected]> Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
1 parent
5886de9d19
commit
adcbb507e9
3 files changed
+68
-19
No files matched your search
@@ -13,10 +13,14 @@ export function Login() {
|
||||
const [qrToken, setQrToken] = useState('');
|
||||
const [found, setFound] = useState<PublicContact | null>(null);
|
||||
const [email, setEmail] = useState('');
|
||||
const [staffPassword, setStaffPassword] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(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,6 +106,24 @@ export function Login() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="card">
|
||||
{isStaff ? (
|
||||
<>
|
||||
<div className="h2" style={{ marginBottom: 6 }}>Staff sign in</div>
|
||||
<div className="muted small" style={{ marginBottom: 12 }}>
|
||||
Enter your staff password to log in.
|
||||
</div>
|
||||
<input
|
||||
className="input"
|
||||
type="password"
|
||||
placeholder="••••••••••"
|
||||
value={staffPassword}
|
||||
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.
|
||||
@@ -107,16 +137,26 @@ export function Login() {
|
||||
onKeyDown={(e) => e.key === 'Enter' && confirm()}
|
||||
autoComplete="off"
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</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 →'}
|
||||
</button>
|
||||
<button className="btn ghost small" style={{ alignSelf: 'flex-start' }} onClick={() => setStep('scan')}>
|
||||
← Different lanyard
|
||||
</button>
|
||||
<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>
|
||||
</section>
|
||||
);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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: <resolved contact 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).
|
||||
|
||||
|
||||
Reference in new issue
Block a user