Changeset 7881080 in Klonkt for src/routes/account.js


Ignore:
Timestamp:
06/18/2026 03:28:34 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
8398935
Parents:
98ecf51
Message:

Hub #3: explicit is_primary flag + shared getPrimarySite() (DRY)

The "oldest site = primary site" assumption was duplicated independently in
resolveSite, hub.js, account.js and admin.js (fragile: if the oldest happened
to be an artist site, the hub home would be wrong). Now:

  • sites.is_primary column + backfill (marks the oldest if none is primary yet; ensurePrimarySite sets it on fresh installs) → existing behaviour exactly preserved.
  • one getPrimarySite() helper (is_primary, fallback oldest) replaces the 4 copies.
  • god can CHOOSE the primary/main site: ★ button + "primary" badge on /admin/sites (exactly one primary via a transaction).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/routes/account.js

    r98ecf51 r7881080  
    2121import { v4 as uuid } from 'uuid';
    2222import db from '../config/database.js';
     23import { getPrimarySite } from '../middleware/site.js';
    2324import { renderPage } from '../middleware/render.js';
    2425import { requireAuth } from '../middleware/auth.js';
     
    8081  let site = db.prepare('SELECT id, title, tagline, slug, owner_id FROM sites WHERE owner_id = ? ORDER BY created_at LIMIT 1').get(user.id);
    8182  if (!site && user.role === 'god') {
    82     site = db.prepare('SELECT id, title, tagline, slug, owner_id FROM sites ORDER BY created_at LIMIT 1').get();
     83    site = getPrimarySite(); // primaire/hoofd-site als fallback
    8384  }
    8485  return site || null;
Note: See TracChangeset for help on using the changeset viewer.