amber-backend/pb_hooks
Claude 8f2cb994ec The code has to choose the template, not the clock
Sharing a second set of paid accounts with friends means a second template,
and the route was not ready for one. It checked the code and then took the
most recently updated row:

  findRecordsByFilter("onboarding_template", "id != ''", "-updated", 1, 0)

With a single row that is invisible. With two it hands the family's
credentials to friends, or the reverse, decided purely by which row was
edited last, silently and with no error. status.html carried a comment
warning about exactly this: "never create a second".

So the code now selects the row, bound as a filter parameter rather than
concatenated. AMBER_INVITE_CODE becomes a fallback that opens the row
flagged isDefault, which means nobody halfway through setup broke and
Coolify needed no edit; once the family row has its own code the env var
stops mattering. A wrong code and a code with no row behind it give the
same 403, since telling them apart would confirm which codes exist.

Codes live on the rows rather than in more env vars, so a new group is one
row in the admin UI instead of a redeploy, and each code is revocable on its
own. The unique index is partial because PocketBase text fields default to
'' and SQLite calls two empty strings equal.

status.html read the template in three places, all by recency. They now go
through familyTemplate(), which selects on isDefault, so adding a friends
row cannot make the editor wander onto it or make account creation preload
the wrong group. Its one-click preload stays family-only; a group picker
there is left undone rather than half-built.

The website says "rodinný kód" in four places and friends are not family, so
that copy widens. The setup flow also offers "Mám kód" up front now: someone
Richard shares accounts with has nothing to buy, and walking them through
three price lists first would be actively misleading.

Verified against PocketBase 0.39.6 with two rows and friends as the most
recently updated, the state that used to break: each code resolved to its own
credentials, the legacy env code resolved to family via isDefault, wrong and
empty codes gave 403, a duplicate code was refused by the index, and
familyTemplate() returned family while -updated returned friends.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-12 21:35:46 +02:00
..
client_logs.pb.js Add client_logs collection for background device diagnostics (feedback 2 §4) 2026-07-23 11:49:04 +02:00
device_auth.pb.js fix(device-auth): inline helpers into each hook handler (JSVM scope) 2026-07-19 19:48:03 +02:00
device_page.pb.js device approve page: manual code-entry for the QR-less path (#55) 2026-07-20 11:06:51 +02:00
onboarding.pb.js The code has to choose the template, not the clock 2026-08-12 21:35:46 +02:00
profile_pin.pb.js Add /api/amber/set-pin: hidden pinHash rejects client writes (#13/#14) 2026-07-21 21:29:02 +02:00
status.pb.js Dashboard: error history, and which publish owns it 2026-08-05 21:34:42 +02:00
update.pb.js Auto-update backend: releases collection + gated manifest (#16) 2026-07-20 11:36:03 +02:00
web.pb.js Shadow the stale pb_public pages the deploy leaves behind 2026-08-07 02:13:31 +02:00
whoami.pb.js Phase 2: /api/amber/whoami token introspection for amber-api 2026-07-25 17:52:43 +02:00