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:
@@ -1,12 +1,13 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useAccess } from '@xenia/access'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import PinPad from '../components/PinPad'
|
||||
import useAuthStore from '../store/authStore'
|
||||
import client from '../api/client'
|
||||
import { apiError } from '../api/errors'
|
||||
import { assetUrl, deliveryMode, getActiveVenue } from '../config/server'
|
||||
import { clearSignedOut, signedOutReason, signedOutText } from '../logic/signedOut'
|
||||
|
||||
|
||||
// ─── Waiter card ──────────────────────────────────────────────────────────────
|
||||
@@ -89,6 +90,9 @@ function WaiterCard({ waiter, onClick }) {
|
||||
// Sends POST /api/auth/login {client: "waiter", user_id | username, pin | password}. The
|
||||
// server's refusals (wrong PIN, one session per waiter, no waiter app for this account…)
|
||||
// are shown in the user's language.
|
||||
// 6F.7: signed in on another phone (rule "ask", auth.session_elsewhere {device, since}): the
|
||||
// page asks; Continue sends the same sign-in with replace: true and the other phone is
|
||||
// signed out at once. Why this phone was signed out (logic/signedOut.js) shows on top.
|
||||
|
||||
export default function LoginPage() {
|
||||
const { t } = useTranslation('waiter')
|
||||
@@ -107,6 +111,9 @@ export default function LoginPage() {
|
||||
const [error, setError] = useState('')
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [attempt, setAttempt] = useState(0) // remounts the PIN pad (clears the dots) after a miss
|
||||
const [elsewhere, setElsewhere] = useState(null) // { secret, device, since }: asking before taking over
|
||||
const [outReason] = useState(signedOutReason)
|
||||
const { formatTime } = useFormat()
|
||||
|
||||
const loadWaiters = useCallback(() => {
|
||||
setLoadingWaiters(true)
|
||||
@@ -129,17 +136,23 @@ export default function LoginPage() {
|
||||
.finally(() => setLoadingWaiters(false))
|
||||
}, [typeUsername, mode])
|
||||
|
||||
async function signIn(secret) {
|
||||
async function signIn(secret, replace = false) {
|
||||
const who = typeUsername ? { username: username.trim() } : { user_id: selectedWaiter?.id }
|
||||
if (!who.username && who.user_id == null) return
|
||||
setError('')
|
||||
setElsewhere(null)
|
||||
setLoading(true)
|
||||
try {
|
||||
const { data } = await client.post('/api/auth/login', { client: 'waiter', ...who, ...secret },
|
||||
const { data } = await client.post('/api/auth/login', { client: 'waiter', ...who, ...secret, ...(replace ? { replace: true } : {}) },
|
||||
{ xenia: { ignoreUnauthorized: true, noOverride: true } })
|
||||
clearSignedOut()
|
||||
login({ id: data.user.id, username: data.user.username, role: data.user.role }, data.access_token)
|
||||
navigate('/tables', { replace: true })
|
||||
} catch (err) {
|
||||
if (err.xenia?.code === 'auth.session_elsewhere') {
|
||||
setElsewhere({ secret, device: err.xenia.params?.device, since: err.xenia.params?.since })
|
||||
return
|
||||
}
|
||||
setError(apiError(err, mode === 'password' ? t('login.wrongPassword') : t('login.wrongPin')))
|
||||
setPassword('')
|
||||
setAttempt(a => a + 1)
|
||||
@@ -148,6 +161,15 @@ export default function LoginPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const outNote = outReason && (
|
||||
<p data-testid="signed-out-note" role="status" style={{
|
||||
margin: '0 auto 12px', maxWidth: 480, padding: '10px 14px', borderRadius: 10, fontSize: 14, lineHeight: 1.4,
|
||||
background: 'var(--bg2)', border: '1px solid var(--x-warning)', color: 'var(--text)', textAlign: 'center',
|
||||
}}>
|
||||
{t(signedOutText(outReason))}
|
||||
</p>
|
||||
)
|
||||
|
||||
const venueSwitch = deliveryMode() === 'native' && (
|
||||
<button
|
||||
onClick={() => navigate('/venues')}
|
||||
@@ -185,6 +207,7 @@ export default function LoginPage() {
|
||||
{/* Static header — never scrolls */}
|
||||
<div style={{ flexShrink: 0, padding: '40px 16px 20px', textAlign: 'center' }}>
|
||||
<h1 className="app-title" style={{ marginBottom: 10 }}>Xenia POS</h1>
|
||||
{outNote}
|
||||
<p className="app-subtitle">{t('login.whoAreYou')}</p>
|
||||
{venueSwitch}
|
||||
</div>
|
||||
@@ -231,6 +254,7 @@ export default function LoginPage() {
|
||||
<div className="page page--centered">
|
||||
<div className="login-box" data-testid="login-secret" data-mode={mode}>
|
||||
<h1 className="app-title">XeniaPOS</h1>
|
||||
{outNote}
|
||||
|
||||
{w ? (
|
||||
/* Selected waiter mini-card */
|
||||
@@ -278,7 +302,23 @@ export default function LoginPage() {
|
||||
</>
|
||||
)}
|
||||
|
||||
{mode === 'password' ? (
|
||||
{elsewhere ? (
|
||||
<div data-testid="login-elsewhere" role="alertdialog" aria-labelledby="elsewhere-title"
|
||||
style={{ display: 'grid', gap: 10, marginTop: 12, padding: 14, borderRadius: 12, background: 'var(--bg2)', border: '1px solid var(--border)' }}>
|
||||
<strong id="elsewhere-title" style={{ fontSize: 16, color: 'var(--text)' }}>{t('login.elsewhereTitle')}</strong>
|
||||
<p style={{ margin: 0, fontSize: 14, lineHeight: 1.5, color: 'var(--text)' }}>
|
||||
{t('login.elsewhereBody', { device: elsewhere.device || '?', time: elsewhere.since ? formatTime(elsewhere.since) : '?' })}
|
||||
</p>
|
||||
<button className="btn btn--primary btn--lg" disabled={loading} data-testid="login-elsewhere-continue"
|
||||
onClick={() => signIn(elsewhere.secret, true)}>
|
||||
{loading ? '…' : t('login.elsewhereContinue')}
|
||||
</button>
|
||||
<button className="btn btn--secondary" disabled={loading} data-testid="login-elsewhere-cancel"
|
||||
onClick={() => { setElsewhere(null); setPassword(''); setAttempt(a => a + 1) }}>
|
||||
{t('login.elsewhereCancel')}
|
||||
</button>
|
||||
</div>
|
||||
) : mode === 'password' ? (
|
||||
<form
|
||||
onSubmit={e => { e.preventDefault(); if (password) signIn({ password }) }}
|
||||
style={{ display: 'grid', gap: 10, marginTop: 10 }}
|
||||
|
||||
Reference in New Issue
Block a user