feat(server): handshake token pour un shell embarquant le daemon (app de bureau)
Some checks failed
CI / Build & test (Node 24) (push) Has been cancelled
CI / Pack & boot smoke (Node 22) (push) Has been cancelled
CI / No em/en dashes (push) Has been cancelled
CI / Build & test (Node 22) (push) Has been cancelled

Dans runDaemon, si ARBORETUM_EMIT_TOKEN_FD est fourni, mint un token 'desktop' et l'écrit en JSON {token,url} sur ce descripteur (pipe stdio privé parent-enfant). Additif et gardé : sans la variable, comportement strictement inchangé. Permettra à l'app Electron d'ouvrir la SPA déjà authentifiée sans écran de login. Vérifié (handshake OK), 431 tests.
This commit is contained in:
2026-07-17 17:44:36 +02:00
parent 4798732856
commit de066abb54

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env node #!/usr/bin/env node
import { readFileSync } from 'node:fs'; import { readFileSync, writeSync } from 'node:fs';
import { join, dirname } from 'node:path'; import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
import { loadConfig, type Config } from './config.js'; import { loadConfig, type Config } from './config.js';
@@ -48,6 +48,20 @@ export async function runDaemon(config: Config): Promise<void> {
console.log('Tokens are stored hashed and cannot be re-printed. Create a new one from Settings (or reset the db).'); console.log('Tokens are stored hashed and cannot be re-printed. Create a new one from Settings (or reset the db).');
} }
// Handshake pour un shell embarquant le daemon (app de bureau) : si ARBORETUM_EMIT_TOKEN_FD est
// fourni, on mint un token frais et on l'écrit en JSON sur ce descripteur (pipe stdio privé
// parent<->enfant). Additif : sans cette variable, comportement strictement inchangé. Le token ne
// transite jamais par le renderer et n'est pas affiché.
const emitFd = process.env.ARBORETUM_EMIT_TOKEN_FD;
if (emitFd) {
try {
const token = auth.createToken('desktop');
writeSync(Number(emitFd), `${JSON.stringify({ token, url })}\n`);
} catch (err) {
app.log.warn(`token handshake failed: ${err instanceof Error ? err.message : String(err)}`);
}
}
let shuttingDown = false; let shuttingDown = false;
const shutdown = (signal: string): void => { const shutdown = (signal: string): void => {
if (shuttingDown) return; if (shuttingDown) return;