feat(backend,waiter,terminal,manager): sign-in: ask before signing a waiter's other phone out, usernames on paired screens

- auth.single_session_waiter gains 'ask', the new default (Alembic 0051 moves venues on 'off'
  to it): a second phone gets auth.session_elsewhere {device, since}; Continue retries with
  replace=true and the first phone is signed out at once (live session.ended, reason
  "replaced") and says why on its sign-in page. Only phones count (terminal sessions are
  their own client). refuse_new / end_old unchanged.
- auth.session_ended now carries the reason; the waiter app keeps it until the next sign-in.
- The waiter app sends queued offline ops on every (re)connection, so an order queued on a
  phone that was signed out by another goes out after the next sign-in there (e2e checked).
- auth.terminal_require_username (venue) + Device.require_username (per device, wins):
  GET /api/devices/me/users lists nobody, the screen asks for a username then PIN/password,
  a picked user_id is refused (auth.username_required), "tap" falls back to PIN.
- Manager: Sign-in settings (ask, the new switch), the device dialog's usernames choice.

Plan platform-v2 6F.7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 12:51:37 +02:00
co-authored by Claude Opus 5.5
parent 3eeafb565a
commit 7706bf2470
31 changed files with 494 additions and 41 deletions
+47
View File
@@ -596,6 +596,53 @@ try {
await a.getByRole('button', { name: /Dark theme/ }).click()
await a.reload()
// ── 6F.7: "ask" (the default): the second phone asks; Continue signs the first one out and it
// says why; an order queued offline on the first phone goes out after it signs in again ──
{
await setting(boss, 'auth.single_session_waiter', 'ask')
const busy7 = new Set((await api('GET', '/api/orders/', { token: boss })).map(o => o.table_id))
const tq = (await api('GET', '/api/tables/', { token: boss })).find(x => x.is_active !== false && !busy7.has(x.id))
const status7 = async () => (await api('GET', `/api/tables/${tq.id}/status`, { token: boss })).active_order_id
await a.goto(`${APP}/tables/${tq.id}/add?new=1`)
await addOn(tq.id, plain)
await ctxA.setOffline(true)
await a.getByTestId('cart-open').click()
await waitFor(async () => (await total().innerText().catch(() => '')).includes('offline'), 30_000, 1000)
await a.getByRole('button', { name: /^(SEND|SUMMARY)/ }).last().click()
if (await shown(a, 'summary-total', 3000)) await a.getByRole('button', { name: /SEND/ }).last().click()
await sleep(1500)
// the second phone
await b.reload()
await b.getByTestId('waiter-card').filter({ hasText: 'Κωνσταντίνου' }).click({ timeout: 10_000 })
await pin(b, '3302')
const asked = await shown(b, 'login-elsewhere', 5000)
const askText = await b.getByTestId('login-elsewhere').innerText().catch(() => '')
r.check('6F.7: a second phone asks (where, since when) instead of refusing', asked && /\d\d:\d\d/.test(askText) && !(await tokenOf(b)), askText.replace(/\s+/g, ' '))
await b.screenshot({ path: path.join(OUT, 'waiter-signed-in-elsewhere.png') })
await b.getByTestId('login-elsewhere-continue').click()
await b.waitForURL(u => u.pathname !== '/login', { timeout: 10_000 }).catch(() => {})
r.check('6F.7: Continue signs this phone in', !!(await tokenOf(b)) && await pathOf(b) !== '/login', await pathOf(b))
// the first phone comes back: signed out, says why, the order still queued
await ctxA.setOffline(false)
const outA = await a.waitForURL(u => u.pathname === '/login', { timeout: 45_000 }).then(() => true).catch(() => false)
const noteA = await a.getByTestId('signed-out-note').innerText({ timeout: 10_000 }).catch(() => '')
r.check('6F.7: the first phone, back online, is signed out and says why', outA && /another device|άλλη συσκευή/.test(noteA), noteA)
await a.screenshot({ path: path.join(OUT, 'waiter-signed-out-replaced.png') })
r.check('6F.7: its order queued offline was not sent with the ended session', !(await status7()))
// it signs in again (asks: the second phone now); the second phone leaves at once (live)
await a.getByTestId('waiter-card').filter({ hasText: 'Κωνσταντίνου' }).click({ timeout: 10_000 })
await pin(a, '3302')
await a.getByTestId('login-elsewhere-continue').click({ timeout: 5000 })
await a.waitForURL(u => u.pathname !== '/login', { timeout: 10_000 }).catch(() => {})
const outB = await b.waitForURL(u => u.pathname === '/login', { timeout: 10_000 }).then(() => true).catch(() => false)
const noteB = await b.getByTestId('signed-out-note').innerText({ timeout: 5000 }).catch(() => '')
r.check('6F.7: the other phone is signed out at once (live) and says why', outB && /another device|άλλη συσκευή/.test(noteB), noteB)
const flushed = await waitFor(status7, 30_000, 1000)
r.check('6F.7: …and the order queued offline goes out after signing in again', !!flushed)
if (flushed) await api('DELETE', `/api/orders/${flushed}`, { token: boss }).catch(() => {})
await a.goto(`${APP}/tables`)
}
// ── Signing out ends the session on the server: the second phone can sign in ─
await a.getByRole('button', { name: 'demo_maria' }).first().click({ timeout: 10_000 })
await a.getByRole('button', { name: /Sign out/ }).last().click()