refactor(connect): one live connection, no token in any address (SSE removed)
Plan step 4.0. Owner (2026-11-17): no phone in use needs to keep working, so no
compatibility path.
- Removed the SSE channel: routers/sse.py (/api/sse/stream, which still accepted a JWT whose
session had ended — a signed-out phone could keep listening), services/sse_bus.py (every
backend module now calls services/ws_bus.broadcast_sync directly), waiter useSSE.js.
- Credentials only in the first frame: the waiter's useWebSocket and the manager's
LiveProvider send {token} there like the terminal; routers/ws.py no longer reads ?token=
(a token in a URL ends up in proxy and server logs).
- Waiter: SSEContext → LiveContext (LiveProvider, useLiveContext, liveAlive, the
'live-event' / 'live-reconnected' window events), dead SSE compat code removed.
- Tests: a token in the address is refused, /api/sse/stream is 404; e2e browser (3 delivery
modes) and manager assert no token in the live connection's address. Android taps now
wait for their element (the fixed sleeps made the suite flaky, KI-009).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -300,7 +300,7 @@ export default function ChatThreadPage() {
|
||||
// ── SSE wiring ────────────────────────────────────────────────────────────────
|
||||
|
||||
useEffect(() => {
|
||||
function onSSE(e) {
|
||||
function onLive(e) {
|
||||
const { type, data } = e.detail
|
||||
// conversationId from useParams is a string; SSE payload has an integer
|
||||
if (type === 'chat_message' && String(data.conversation_id) === conversationId) {
|
||||
@@ -338,8 +338,8 @@ export default function ChatThreadPage() {
|
||||
updateLastRead(data.conversation_id, data.user_id, data.read_at)
|
||||
}
|
||||
}
|
||||
window.addEventListener('sse-event', onSSE)
|
||||
return () => window.removeEventListener('sse-event', onSSE)
|
||||
window.addEventListener('live-event', onLive)
|
||||
return () => window.removeEventListener('live-event', onLive)
|
||||
}, [conversationId, addMessage, markRead, upsertConversation, updateLastRead])
|
||||
|
||||
// ── Send message ──────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -1197,7 +1197,7 @@ export default function TableDetailPage() {
|
||||
}, [tableId, standaloneOrderId]) // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
useEffect(() => {
|
||||
function onSSE(e) {
|
||||
function onLive(e) {
|
||||
const { type, data } = e.detail
|
||||
if ((type === 'kds_item_updated' || type === 'kds_order_updated') && order && data.order_id === order.id) {
|
||||
load()
|
||||
@@ -1215,8 +1215,8 @@ export default function TableDetailPage() {
|
||||
navigate('/tables', { replace: true })
|
||||
}
|
||||
}
|
||||
window.addEventListener('sse-event', onSSE)
|
||||
return () => window.removeEventListener('sse-event', onSSE)
|
||||
window.addEventListener('live-event', onLive)
|
||||
return () => window.removeEventListener('live-event', onLive)
|
||||
}, [order?.id, tableId])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -377,8 +377,8 @@ export default function TableListPage() {
|
||||
|
||||
useEffect(() => {
|
||||
const handler = () => load()
|
||||
window.addEventListener('sse-reconnected', handler)
|
||||
return () => window.removeEventListener('sse-reconnected', handler)
|
||||
window.addEventListener('live-reconnected', handler)
|
||||
return () => window.removeEventListener('live-reconnected', handler)
|
||||
}, [])
|
||||
|
||||
useEffect(() => { if (connStatus === 'online') setOffline(false) }, [connStatus])
|
||||
@@ -465,7 +465,7 @@ export default function TableListPage() {
|
||||
// ── SSE live updates ───────────────────────────────────────────────────────
|
||||
useEffect(() => {
|
||||
if (isOffline) return
|
||||
function onSSE(e) {
|
||||
function onLive(e) {
|
||||
const { type, data } = e.detail
|
||||
if (type === 'order_updated' || type === 'order_paid') {
|
||||
client.get(`/api/orders/${data.order_id}`)
|
||||
@@ -499,8 +499,8 @@ export default function TableListPage() {
|
||||
}).catch(() => {})
|
||||
}
|
||||
}
|
||||
window.addEventListener('sse-event', onSSE)
|
||||
return () => window.removeEventListener('sse-event', onSSE)
|
||||
window.addEventListener('live-event', onLive)
|
||||
return () => window.removeEventListener('live-event', onLive)
|
||||
}, [isOffline])
|
||||
|
||||
// ── Derived maps ───────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user