A tenant had exactly the users somebody had created with a command on the
server. That is not a missing screen: a shop with an owner and four staff
either shared one password or raised a ticket per person, and a phone app
for the shop floor could not exist while there was one account to sign in
as.
Registration is by invitation, never open signup - the same line already
drawn around creating a company. The code carries the address and the role
and the request carries only a password, so a code that gets forwarded
cannot become somebody else's account, and a staff invitation cannot be
redeemed as an owner. Single use lives in the UPDATE and the account is
created in the same transaction.
Deactivating a member revokes their sessions in that transaction too. An
access token lives twelve hours, so without it "remove their access"
removed it sometime tomorrow. The session list and revoke that go with it
are the benefit of opaque tokens the product had been paying for and never
collecting: nothing could say what was signed in, let alone stop one.
Face images now work on a deployment with no object storage, which was
every local install and every self-hosted site - the arrivals feed said
"not storing customer photos" for every customer forever, on the screen
whose whole job is to show a face. Bounded to one row per visitor, so it
grows with the customer base and not with footfall; the bucket stays
primary wherever one exists.
Image.auth says whether a URL needs the session, because a browser img
cannot load one that does, a mobile image view can, and a webview can do
neither - the desktop client resolves those to a data URI in Go.
Found by running it, not by tests:
* UPDATE ... RETURNING gives the value AFTER the update, so the prune
read back empty keys, deleted nothing, and the table grew with
footfall exactly as if it were not there. The fake agreed with either
version; only the live Postgres test caught it.
* Trusting only the auth flag broke every shop card, because Sites.jsx
rebuilt a partial snapshot object and dropped it. A relative URL is
now sufficient on its own.
* ago() renders a future time as "just now", so a code valid for a week
read "expires just now".
Verified live against real Postgres: invite, preview, escalation refused,
register into a session, replay 404, staff forbidden, device revoked and
401 at once, last owner refused, and a 92,405-byte camera JPEG stored,
served to its owner, 401 with no session, 404 to another tenant, and
rendered in a browser.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HViLj9gYNRtSr7YVZmW5sn
100 lines
3.5 KiB
JavaScript
100 lines
3.5 KiB
JavaScript
import { useEffect, useState } from 'react'
|
|
import { api, signedIn, clearTokens } from './api.js'
|
|
import Login from './views/Login.jsx'
|
|
import Sites from './views/Sites.jsx'
|
|
import Live from './views/Live.jsx'
|
|
import CamerasView from './views/Cameras.jsx'
|
|
import Assistant from './views/Assistant.jsx'
|
|
import Clients from './views/Clients.jsx'
|
|
import Team from './views/Team.jsx'
|
|
|
|
// A platform admin has no client of their own, so the tenant screens have
|
|
// nothing to show them. Rather than render empty pages, they get the one screen
|
|
// that is theirs.
|
|
//
|
|
// Customers and Reports were removed from the navigation - not deleted, the
|
|
// views and their API routes are untouched - the same trim the desktop app
|
|
// already made and for the same reason: this is the screen somebody opens to
|
|
// find out whether their shops are WORKING. A customer search and a
|
|
// month-on-month chart are a different job, and putting them in the same nav
|
|
// implies the estate is healthy enough to be worth reporting on before anyone
|
|
// has checked. They come back when there is something to say with them.
|
|
const TENANT_VIEWS = [
|
|
{ id: 'sites', label: 'Shops', View: Sites },
|
|
{ id: 'live', label: 'Live', View: Live },
|
|
{ id: 'cameras', label: 'Cameras', View: CamerasView },
|
|
{ id: 'team', label: 'Team', View: Team },
|
|
]
|
|
const ADMIN_VIEWS = [
|
|
{ id: 'clients', label: 'Companies', View: Clients },
|
|
]
|
|
|
|
export default function App() {
|
|
const [user, setUser] = useState(null)
|
|
const [booting, setBooting] = useState(true)
|
|
const [view, setView] = useState('sites')
|
|
const [asking, setAsking] = useState(false)
|
|
|
|
useEffect(() => {
|
|
(async () => {
|
|
if (signedIn()) {
|
|
try { setUser(await api.me()) } catch { clearTokens() }
|
|
}
|
|
setBooting(false)
|
|
})()
|
|
}, [])
|
|
|
|
if (booting) {
|
|
return <div className="boot"><span className="spinner" aria-hidden="true" />Loading…</div>
|
|
}
|
|
if (!user) return <Login onSignedIn={setUser} />
|
|
|
|
const isAdmin = user.role === 'admin' && !user.client_id
|
|
const views = isAdmin ? ADMIN_VIEWS : TENANT_VIEWS
|
|
const current = views.find(v => v.id === view) || views[0]
|
|
const Current = current.View
|
|
|
|
const signOut = async () => { await api.logout(); setUser(null) }
|
|
|
|
return (
|
|
<div className="app">
|
|
<header className="topbar">
|
|
<div className="brand">
|
|
<span className="mark" aria-hidden="true" />
|
|
<div>
|
|
<strong>Behavision</strong>
|
|
<span className="org">{user.client_name || 'Loyaly platform'}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<nav className="tabs">
|
|
{views.map(v => (
|
|
<button
|
|
key={v.id}
|
|
onClick={() => setView(v.id)}
|
|
aria-current={current.id === v.id ? 'page' : undefined}
|
|
>{v.label}</button>
|
|
))}
|
|
</nav>
|
|
|
|
<div className="who">
|
|
<button className={'ask-btn' + (asking ? ' on' : '')}
|
|
onClick={() => setAsking(a => !a)}>
|
|
<span aria-hidden="true">✳</span> Ask
|
|
</button>
|
|
<span className="name">{user.full_name || user.email}</span>
|
|
<span className="role">{isAdmin ? 'platform admin' : user.role}</span>
|
|
<button className="ghost" onClick={signOut}>Sign out</button>
|
|
</div>
|
|
</header>
|
|
|
|
<div className={'with-assistant' + (asking ? ' open' : '')}>
|
|
<main className="page">
|
|
<Current user={user} />
|
|
</main>
|
|
<Assistant open={asking} onClose={() => setAsking(false)} />
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|