feat(waiter): configurable server/venue layer for native app and plain-HTTP browser mode
New waiter_pwa/src/config/server.js is the single place that knows where the backend is. Served by the venue's server (https domain or http://<LAN IP>) nothing changes: same-origin URLs and the original storage keys, so existing installs keep their token and unsynced offline queue. With an active venue (native app, or dev builds with VITE_SERVER_URL) URLs become absolute and all venue data is namespaced by siteId: token/savedUsername keys, the Dexie DB (pos_snapshot__<siteId>, which also covers the WS cursor), favorites and table-view prefs. Switching venue reloads the app. - api client baseURL, WebSocket and SSE URLs routed through the layer - product images / waiter avatars rendered via assetUrl() - service-worker update prompt skipped in native builds - InstallAppBanner: shown only in plain-HTTP browser mode and only when VITE_APP_DOWNLOAD_URL is set at build time (dismiss for 7 days) - VITE_SERVER_URL override is DEV-only (a URL-controlled server in prod would let a crafted link capture PINs) - pack README: rule CS-8 on never assuming same-origin Verified with Playwright/Edge against a local backend: prod build same-origin, prod build via LAN IP over plain HTTP (insecure context, no SW, banner shown), and dev build pointed at the backend by URL - all three log in, reach /tables and receive the WebSocket 'ready' frame; storage keys and IndexedDB names are as expected. Lint: no new problems (103 before/after). Build passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,26 +1,30 @@
|
||||
import { create } from 'zustand'
|
||||
import { storageKey } from '../config/server'
|
||||
|
||||
const savedUsername = localStorage.getItem('savedUsername')
|
||||
const TOKEN_KEY = storageKey('token')
|
||||
const USERNAME_KEY = storageKey('savedUsername')
|
||||
|
||||
const savedUsername = localStorage.getItem(USERNAME_KEY)
|
||||
|
||||
const useAuthStore = create((set) => ({
|
||||
user: null,
|
||||
token: localStorage.getItem('token') || null,
|
||||
token: localStorage.getItem(TOKEN_KEY) || null,
|
||||
savedUsername: savedUsername || null,
|
||||
|
||||
login(user, token) {
|
||||
localStorage.setItem('token', token)
|
||||
localStorage.setItem('savedUsername', user.username)
|
||||
localStorage.setItem(TOKEN_KEY, token)
|
||||
localStorage.setItem(USERNAME_KEY, user.username)
|
||||
set({ user, token, savedUsername: user.username })
|
||||
},
|
||||
|
||||
logout() {
|
||||
localStorage.removeItem('token')
|
||||
localStorage.removeItem('savedUsername')
|
||||
localStorage.removeItem(TOKEN_KEY)
|
||||
localStorage.removeItem(USERNAME_KEY)
|
||||
set({ user: null, token: null, savedUsername: null })
|
||||
},
|
||||
|
||||
clearSavedUsername() {
|
||||
localStorage.removeItem('savedUsername')
|
||||
localStorage.removeItem(USERNAME_KEY)
|
||||
set({ savedUsername: null })
|
||||
},
|
||||
}))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { create } from 'zustand'
|
||||
import { persist } from 'zustand/middleware'
|
||||
import { storageKey } from '../config/server'
|
||||
|
||||
// density: '1x1' | '2x1' | '2x2' | '4x1' | '4x2' | '4x3'
|
||||
// ownerFilter: 'all' | 'mine'
|
||||
@@ -60,7 +61,7 @@ const useTableViewStore = create(
|
||||
}),
|
||||
}),
|
||||
{
|
||||
name: 'table-view-prefs',
|
||||
name: storageKey('table-view-prefs'), // zone IDs are venue-specific
|
||||
// future: could sync to backend here
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { create } from 'zustand'
|
||||
import { persist } from 'zustand/middleware'
|
||||
import client from '../api/client'
|
||||
import { storageKey } from '../config/server'
|
||||
|
||||
const SETTINGS_KEY = 'waiter-favorites'
|
||||
|
||||
@@ -94,7 +95,7 @@ const useWaiterFavoritesStore = create(
|
||||
} catch { /* best-effort */ }
|
||||
},
|
||||
}),
|
||||
{ name: SETTINGS_KEY }
|
||||
{ name: storageKey(SETTINGS_KEY) } // product IDs are venue-specific
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user