fix(auth): show the shared-wallet flow in dev; hide re-import when already connected
The access barrier's shared-wallet steps are gated on hasSharedWallet(), which reads a global set only by build.ts's compile-time `define`. The src-served paths (bun run dev AND bun run start) bundle index.html via Bun's HTML import, which applies no define and inlines neither `process.env` nor `bun --define` (verified) — so FESTIPOD_SHARED_WALLET_PASSWORD passed to `bun run dev` never reached the frontend, and the barrier showed the identifier-only variant. Expose the config at runtime instead: src/index.ts serves /festipod-config.json (+ /shared-wallet.ngw), and the entry (frontend.tsx) fetches it, sets the global, then dynamically imports App so sharedWallet.ts reads it on eval. In a build.ts bundle the value is inlined via define, so the fetch is skipped (NODE_ENV). Verified in a headless browser: FESTIPOD_SHARED_WALLET_PASSWORD=1 bun run dev now renders the download + import steps AND the identifier field, no console errors. Also: only show the download/import steps when status !== 'connected' — after a faux-logout the wallet is still open, so re-import must not be offered (just the identifier). Documents the build-define-vs-runtime-config pitfall in tech-stack. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,13 @@ Le serveur sert `src/index.html`, qui charge `src/app/frontend.tsx` (voir `app-a
|
||||
## Détails de `build.ts` et du serveur
|
||||
|
||||
- `build.ts` scanne `src/**/*.html` comme entrypoints (aujourd'hui un seul : `src/index.html`), `target: 'browser'`, minify + sourcemap linked, plugin `bun-plugin-tailwind`. Ajouter un 2e `.html` créerait un 2e bundle.
|
||||
- `src/index.ts` (`Bun.serve`) sert : `/reports/cucumber` (rapport HTML), des stubs `/api/hello*`, et un **catch-all `/*` → `src/index.html`** (routing SPA, doit rester en dernier). HMR si `NODE_ENV !== 'production'`, port via `PORT`.
|
||||
- `src/index.ts` (`Bun.serve`) sert : `/reports/cucumber` (rapport HTML), des stubs `/api/hello*`, `/festipod-config.json` + `/shared-wallet.ngw` (config runtime, voir ci-dessous), et un **catch-all `/*` → `src/index.html`** (routing SPA, doit rester en dernier). HMR si `NODE_ENV !== 'production'`, port via `PORT`.
|
||||
|
||||
## Globals de build vs config runtime (piège du wallet partagé)
|
||||
|
||||
`build.ts` injecte des **globals à la compilation** via `define` (p. ex. `__FESTIPOD_SHARED_WALLET_PASSWORD__` depuis `FESTIPOD_SHARED_WALLET_PASSWORD`, `__FESTIPOD_ACCESS_GATE_DISABLED__`). **Piège** : le serveur `src/index.ts` (utilisé par `bun run dev` ET `bun run start`) bundle `index.html` via l'import HTML de Bun, qui **n'applique aucun `define`** — ni `bun --define` ni `process.env` ne s'y propagent (vérifié). Donc une variable d'env passée à `bun run dev` n'atteint pas le bundle frontend par ce chemin.
|
||||
|
||||
Pour ces chemins servis depuis `src/`, la config passe donc au **runtime** : `src/index.ts` expose `/festipod-config.json` (lu depuis l'env), et l'entrée `src/app/frontend.tsx` la **fetch d'abord**, pose le global, **puis importe l'app dynamiquement** (`await import('./App')`) — ainsi `sharedWallet.ts` lit la valeur à son évaluation. Dans un bundle `build.ts` la valeur est déjà inline par `define`, donc le fetch est court-circuité (`NODE_ENV === 'production'`). Conséquence pratique : pour voir le flux « portefeuille partagé » en dev, lancer `FESTIPOD_SHARED_WALLET_PASSWORD=1 bun run dev` (+ `FESTIPOD_SHARED_WALLET_FILE=<.ngw>` pour un vrai téléchargement).
|
||||
|
||||
## Le harness de test est buildé à part
|
||||
|
||||
|
||||
Reference in New Issue
Block a user