Admin dashboard (phase 1): users, disable, invite-gated signup

Adds an operator dashboard for self-hosters, gated on a passkey-
authenticated admin flag (ADMIN_UIDS env) and enforced server-side.

Backend:
- ADMIN_UIDS / INVITE_ONLY env (both off by default, OSS-friendly).
- Invite codes in db.json; /api/register gated when INVITE_ONLY, code
  burned on successful signup.
- disabled users are rejected by readSession — locked out everywhere.
- /api/admin/{users,user,user/disable,invites,invites/new,invites/revoke}
  behind an admin guard; /api/config exposes invite_only to the login UI.
- admin flag surfaced on /api/me, register/verify, login/verify.

Frontend:
- New /admin route + Settings link, shown only to admins: user list with
  workout counts and last-sync, disable/enable, invite generation, and a
  per-user workout-history drill-down.
- Registration sheet shows an invite-code field when the instance is
  invite-only.

Phase 2 (live 'training now' via a heartbeat) is separate.
This commit is contained in:
Duarte Santos committed 2026-07-22 01:58:33 +02:00
1 parent dabffdebc0
commit 046217079c
18 files changed
+338 -23

No files matched your search

+2 -2
View File
@@ -45,8 +45,8 @@ function credToJSON(cred) {
}
return out
}
export async function passkeyRegister(name) {
const { cid, options } = await api('/api/register/options', { method: 'POST', body: JSON.stringify({ name }) })
export async function passkeyRegister(name, code) {
const { cid, options } = await api('/api/register/options', { method: 'POST', body: JSON.stringify({ name, code: code || '' }) })
const cred = await navigator.credentials.create({ publicKey: toCreationOptions(options) })
const res = await api('/api/register/verify', { method: 'POST', body: JSON.stringify({ cid, credential: credToJSON(cred) }) })
return res.user