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
+31 -3
View File
@@ -5,6 +5,9 @@
// password your name, then your password
// POST /api/auth/login {client: "terminal", user_id, pin|password} with the device header;
// the session belongs to this screen only.
// Usernames (6F.7, me.require_username: the venue's auth.terminal_require_username or the
// device's own choice): nobody is listed; the person types their username, then the PIN or
// password ("tap" never applies then: the server answers pin instead).
import { useCallback, useEffect, useState } from 'react'
import { ArrowLeft } from 'lucide-react'
import { useAccess } from '@xenia/access'
@@ -27,12 +30,14 @@ export default function SignInScreen() {
const [error, setError] = useState('')
const [busy, setBusy] = useState(false)
const mode = me.login_mode
const typeName = !!me.require_username
const loadUsers = useCallback(() => {
if (typeName) { setUsers([]); return }
client.get('/api/devices/me/users', quiet)
.then(r => { setUsers(r.data); setLoadError(null) })
.catch(err => setLoadError(errorMessage(err, t)))
}, [t])
}, [t, typeName])
useEffect(() => { loadUsers() }, [loadUsers, me.login_mode])
useEffect(() => {
const id = setInterval(loadUsers, USERS_REFRESH_MS)
@@ -41,7 +46,8 @@ export default function SignInScreen() {
useLiveEvent('ready', loadUsers)
const login = async secret => {
const { data } = await client.post('/api/auth/login', { client: 'terminal', user_id: picked?.id ?? secret.user_id, ...secret }, quiet)
const who = picked?.username ? { username: picked.username } : { user_id: picked?.id ?? secret.user_id }
const { data } = await client.post('/api/auth/login', { client: 'terminal', ...who, ...secret }, quiet)
signIn(data.access_token)
}
@@ -61,7 +67,11 @@ export default function SignInScreen() {
<p className="text-body text-ink-2">{me.name}{venue?.name ? ` · ${venue.name}` : ''}</p>
</header>
{!picked && (
{!picked && typeName && (
<UsernameForm onSubmit={username => { setError(''); setPicked({ username, full_name: username }) }} />
)}
{!picked && !typeName && (
loadError ? <EmptyState title={loadError} action={<Button variant="secondary" onClick={loadUsers}>{t('common:actions.retry')}</Button>} />
: !users ? <Spinner />
: users.length === 0
@@ -100,6 +110,24 @@ export default function SignInScreen() {
)
}
function UsernameForm({ onSubmit }) {
const { t } = useTranslation('terminal')
const [username, setUsername] = useState('')
const submit = e => {
e.preventDefault()
if (username.trim()) onSubmit(username.trim())
}
return (
<form onSubmit={submit} className="bg-surface border border-line rounded-card shadow-raised p-6 grid gap-4 w-full max-w-sm" data-testid="username-form">
<Field label={t('signIn.username')} hint={t('signIn.typeUsername')}>
<Input value={username} onChange={e => setUsername(e.target.value)} autoFocus autoComplete="off"
autoCapitalize="none" spellCheck={false} data-testid="username-input" />
</Field>
<Button type="submit" disabled={!username.trim()}>{t('signIn.next')}</Button>
</form>
)
}
function PasswordForm({ onSubmit, error }) {
const { t } = useTranslation('terminal')
const [password, setPassword] = useState('')