Skip to content

Families and the superadmin

The plan for two things the app needs next, and the order to build them in:

  1. More pairs of a senior and a Loved One. Each Loved One sees and edits only the memories of their own senior. The running example is Lin (a senior, on the phone) and Benji (her Loved One, on the web). When Benji signs in, he can edit Lin's memories and nobody else's.
  2. A superadmin account that can see and change every account: who exists, who reaches which memory bank, names, emails, and passwords.

Phase 1 is built (October 9, 2026) and waits for its deploy; the rest is planned. Accounts and roles has the model this plan rests on; Adding a person to test the app is the flow the scripts belong to.

What already works

Most of the Lin and Benji scenario is already how the Worker behaves; the gaps are in how accounts get made and in what the phone shows.

  • Access hangs off the bank, not the role. A senior owns one memory bank (memory_banks), and a Loved One reaches it through a bank_members row. bankAccessFor in apps/api/src/auth.ts answers every content route: no row, no access, and a bank you cannot reach answers 404 so its id cannot even be probed. The route tests prove this with an "outsider" account (apps/api/tests/routes/helpers.ts).
  • The web app lists only what the account can reach. GET /banks returns the banks the signed-in user owns or is a member of. With one bank, the web's Home is headed "Lin's phone" and has no selector (until November 12, 2026, every page said "Whose memories: Lin"). So once Benji has exactly one membership row, he sees exactly Lin.
  • A senior with no memories in the app (Lin, like Thomas today) gets memories from the photos added under Photos, which lists them first.
  • Pairing is per bank. Benji makes a code on the web for Lin's bank; Lin's phone trades it for a two-year session that belongs to Lin's account, so her app opens are logged under her name.
  • pnpm add-person makes a senior's account and bank (src/people.ts).

What gets in the way

  1. There is no way to make a Loved One account except hand-written SQL with a password hash from hashPassword. Thomas's and Lisa's cloud accounts were made that way.
  2. add-person gives every Loved One access to the new bank. It inserts a manage row for every account with an email. If Benji exists before Lin is added, he gets Lin, but so does everyone else; if Lin is added first, Benji gets nothing. The grant has to become explicit.
  3. There is no superadmin. Thomas and Lisa see every bank only because a membership row was added for each one by hand, and every new bank needs more rows. The Worker has no notion of an account that reaches everything.
  4. The phone's roster is fixed in the build. The pairing answer carries the senior's name, and the phone matches it against Tom, Nyna, Thomas, and Lisa. "Lin" matches nobody, so her phone stays on whichever person was chosen in Settings (the guide says to choose Thomas). Her data is right, since the session is hers, but Settings shows the wrong name.
  5. Passwords cannot be changed except by hand, and changing one does not end the old sessions.

The scenario, as acceptance checks

When the first two phases are done, this is what happens, in order:

  1. Thomas runs two commands (later, uses the Accounts page): one makes Lin's account and bank, the other makes Benji's Loved One account with manage access to Lin's bank and nothing else.
  2. Benji signs in on the family web app. The header says "Benji ยท Loved One". Home is headed "Lin's phone". There is no selector, because he has one person.
  3. Benji adds photos under Photos, with descriptions and memory details. They appear under Photos as Lin's memories.
  4. Any request Benji's browser makes for another bank, even Tom's real bank id, answers 404 "No such memory bank".
  5. Benji opens Connect a phone and makes a code. On Lin's phone, Settings shows Lin as who is using the app after Use Code succeeds, and the start screen's Memories session shows the photos Benji added.
  6. Thomas signs in. Every bank is in Whose memories, on Home, Lin's included, with no membership row needed. An Accounts section lists Lin, Benji, and everyone else, with what each can reach.
  7. Benji never sees an Accounts section, and a request to any admin route from his session answers 403.

Phase 1: Benji edits only Lin

Data, Worker, and two scripts. No new web screens; the web already behaves correctly once the data is right. This phase is enough to put Lin and Benji on the system.

The superadmin flag

Migration 0010_superadmin.sql:

ALTER TABLE users ADD COLUMN superadmin INTEGER NOT NULL DEFAULT 0
  CHECK (superadmin IN (0, 1));

A flag rather than a third role, for two reasons. The role answers "which experience does this person get" (senior app or Loved One tools), and a superadmin gets the Loved One tools plus one more section, so their role stays admin. And the role column has a CHECK constraint; widening it in SQLite means rebuilding the users table, which every other table references. Adding a column is one statement.

The flag is set in production by one statement for Thomas, after the migration lands:

UPDATE users SET superadmin = 1 WHERE id = 'thomas';

Lisa keeps her membership rows and is unchanged until Thomas decides whether she should also be a superadmin.

Worker

  • UserRow and ApiUser (packages/shared/src/api-types.ts) carry superadmin: boolean; requireUser reads the column, publicUser returns it, so the web can show or hide the Accounts section.
  • bankAccessFor returns manage for a superadmin before looking at memberships, for any bank that exists. It still returns null for a bank that does not exist.
  • GET /banks returns every bank for a superadmin, each with access: 'manage', ordered by senior name.
  • Nothing else changes: every content route already goes through bankAccessFor.

Scripts

people.ts stops granting every emailed account. newPerson takes an optional list of Loved One emails and grants manage to those; with none, the bank has no members, and superadmins reach it anyway. The add-person script gains --loved-one <email> (repeatable).

A new src/loved-ones.ts with newLovedOne(name, email, bankIds, password) builds the SQL for a Loved One: a users row with role admin, the PBKDF2 hash from hashPassword, and one manage row per bank. A new scripts/add-loved-one.ts runs it the way add-person does:

cd ~/Documents/GitHub/SilverApp && pnpm add-person "Lin" --remote
cd ~/Documents/GitHub/SilverApp && pnpm add-loved-one "Benji" benji@example.com --for Lin --remote

The second command generates a password, prints it once, and never stores it anywhere but as a hash. Thomas gives it to Benji out of band. --for names the senior (resolved to bank-lin with personSlug) and may repeat for a Loved One who curates two people. An email that is already taken is refused before anything is written, the way add-person refuses a name that exists.

Both builders are pure functions that return SQL, so the Phase 3 admin routes can reuse them: one definition of what an account is, whether it is made from the terminal or the web.

Tests

  • tests/people.test.ts: the grant goes to the named Loved Ones only, and to nobody when none are named.
  • tests/loved-ones.test.ts: the user row, the hash format, one row per bank, an apostrophe in a name stays safe, a bad email is refused.
  • tests/routes/: the helpers gain a superadmin account with no memberships. A superadmin reads and writes a bank they are not a member of; GET /banks lists every bank for them; the outsider still gets 404; GET /auth/me carries the flag.
  • apps/web/tests/app.test.tsx: unchanged for Benji's case, which it already covers (one bank, no selector).

Docs and deploy

  • adding-a-tester.md gains the Loved One step and drops the sentence about every Loved One getting access.
  • accounts-and-roles.md gains the superadmin paragraph under the data model and the auth section.
  • Deploy in the usual order: migration, Worker, then the two scripts with --remote, then the UPDATE for Thomas. The web app needs no deploy for Phase 1.

Phase 2: Lin's phone says Lin

A mobile change, so it ships through TestFlight. Today the phone's fourth person slot is Thomas, with no bundled content, and the guide tells a tester to choose it. The change: the pairing answer already carries the senior's name, so the phone keeps it.

  • savePairedToken stores the senior's name beside the token (bank-session-v1.<id> gains a .name entry in secure storage).
  • The roster's slot 3 becomes "whoever paired this phone": seniorById('3') reads its name from the stored pairing, with "Thomas" as the fallback so Thomas's own phone and the dev auto-login keep working, and so every existing test still passes.
  • connect-screen.tsx maps a name that is not on the roster to slot 3 instead of the current selection, then announces "Connected to Lin's family photos" as it does now.
  • Settings > Who is using the app shows the stored name on that radio.
  • Tests: seniors-roster.test.ts ("has nothing for a senior who is not in the roster") still holds, since Lin has no bundled assets. active-senior.test.tsx gains a case where slot 3 is named from a pairing. A connect-screen test pairs as an unknown name and expects slot 3 to be chosen.

This keeps the build's fixed roster, which require() forces on bundled media, while letting any family's senior see their own name. Dropping the roster entirely for release builds (the phone shows only the paired person, and Settings has no switch) is a later step, once Tom's bundled memories move into his bank.

Phase 3: the Accounts section

The superadmin's tools on the web, backed by Worker routes under /admin. Everything is enforced in the Worker; the web only hides what a Loved One cannot do.

Worker routes

All behind requireUser and a new requireSuperadmin (403 "Not allowed" for anyone else; a plain Loved One must not learn what is behind it).

Route What it does
GET /admin/accounts Every account: id, name, email, role, superadmin flag, created, last sign-in, banks and access
POST /admin/accounts A senior (with their bank) or a Loved One (with a password); uses the Phase 1 builders
PATCH /admin/accounts/:id Name, email, superadmin flag
POST /admin/accounts/:id/password Sets a new password and deletes that account's sessions
PUT /admin/banks/:bankId/members/:userId Grants manage or view
DELETE /admin/banks/:bankId/members/:userId Takes access away; the next request from that account already sees it gone

Rules the routes keep:

  • password_hash never leaves the Worker.
  • A superadmin cannot take their own flag away, so the last superadmin cannot lock everyone out.
  • Every change writes an account_changes row (migration 0011: who, what, which account, when). It costs one insert and answers "who changed Benji's access" later.
  • Removing a Loved One from a bank does not delete anything they added. Photos, songs, and memory details stay with the bank.

Web

  • App shows an Accounts row on More when user.superadmin is true (a page in journey.ts; this said "a button in the section nav" until the pages moved to Home and More on November 12, 2026).
  • AccountsSection: a table with proper headers (Name, Role, Email, Reaches, Last sign-in), one row per account, with an Edit button that opens the row's form in place: name, email, superadmin, a checklist of banks with manage or view, and "Set a new password", which shows the new password once. Forms use labeled fields and the page's one status live region, as the other sections do.
  • Two forms above the table: Add a senior (name) and Add a Loved One (name, email, which seniors). Adding a senior shows the next steps from the tester guide, so the superadmin can pair the phone straight away.
  • "Whose memories", on Home, lists every bank for a superadmin, grouped under one heading, and still remembers the last choice.

Tests

  • Route tests: 403 for a Loved One on every admin route; 200 for a superadmin; the self-lockout rule; a password change ends the old session; a removed member gets 404 on the bank afterward; the audit row is written.
  • Web tests (apps/web/tests/): the Accounts button is absent for a Loved One and present for a superadmin; the table is reachable by role and header; adding a Loved One calls the API with the chosen banks.

After this phase the two scripts stay as terminal shortcuts that call the same builders.

Phase 4: later, once families are using it

Not planned in detail. Each is a small step on the model above.

  • Password reset by email, so a Loved One who forgets theirs does not need Thomas. Cloudflare Email Service from the Worker; a reset token table like pairing_codes.
  • Invitations. Instead of handing a password over, the superadmin (or, later, a Loved One with manage access) sends an invite link; the invitee picks their own password. share_codes was designed for the view case and extends to this.
  • A Loved One adds another Loved One to their senior's bank (Benji invites his sister). Manage access would carry the right to invite.
  • Turning an account off (users.disabled_at): sessions refused, content kept. The tester guide's "Taking someone off" section becomes a button.
  • Activity for the superadmin: app opens per senior from app_opens, on the Accounts page.

Decisions (Thomas, October 9, 2026)

  • Flag, not a role, for superadmin, for the reasons above.
  • Thomas is the only superadmin at the start. Lisa keeps her membership rows, which give her every bank that exists today; she is not added to new families' banks unless named.
  • Benji's password is generated and printed once by the script, never chosen on the command line. The Phase 4 invite replaces this.
  • Nyna's bank. A superadmin sees it like any other. Benji, or any other family's Loved One, never does. Nothing new is needed, but anything built for the Accounts page should keep in mind that her profile is not a user (Multiple seniors, "Nyna's profile").

Deploying Phase 1

In this order, from the repo root. The migration must land before the Worker that reads the column.

cd ~/Documents/GitHub/SilverApp && pnpm --filter @senior-health/api migrate:remote
cd ~/Documents/GitHub/SilverApp && pnpm deploy:api
cd ~/Documents/GitHub/SilverApp/apps/api && npx wrangler d1 execute senior-health --remote --env production --command "UPDATE users SET superadmin = 1 WHERE id = 'thomas'"
cd ~/Documents/GitHub/SilverApp && pnpm add-person "Lin" --remote
cd ~/Documents/GitHub/SilverApp && pnpm add-loved-one "Benji" benji@example.com --for Lin --remote

The web app needs no deploy: it already shows only the banks an account can reach. Check afterwards by signing in as Thomas (every bank, Lin's included) and as Benji (Lin only).

Risks and guards

  • Migration before Worker. 0010 must land before the Worker that reads superadmin, as always: migrate:remote, then deploy:api.
  • Never the dev seed in production. The scripts write individual rows; the seed's tokens are public.
  • The grant change in add-person is a behavior change. Anyone added after Phase 1 is reachable by superadmins and named Loved Ones only. The guide must say so, or the next tester's photos will seem to vanish for Lisa if she is not a superadmin.
  • The phone slot. Until Phase 2 ships, Lin's phone shows "Thomas" in Settings while playing Lin's memories. The tester guide already explains this; it stays accurate for the gap.
  • Sessions outlive access. A removed membership takes effect on the next request, because access is read per request. A changed password does not end sessions unless the route deletes them, which Phase 3 does.