diff --git a/docs/migration.md b/docs/migration.md index d944b88..a7463b0 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -26,7 +26,7 @@ where the principal is the C2C installation (`c2c_inst_…`). To upgrade without deleting legacy files: ```bash -c2c broker migrate-auth +c2c broker migrate-auth — merges legacy per-workspace tokens into the installation store; restarts the broker when running so migrated tokens are recognized immediately. ``` This copies live client registrations and unexpired tokens into the diff --git a/src/cli/index.ts b/src/cli/index.ts index 940cbb2..2ba9a3c 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -1451,6 +1451,16 @@ brokerCmd `Migrated ${result.tokensMigrated} token(s) from ${result.sourceFiles.length} legacy file(s) to ${result.installationId}` ); say("Legacy auth files were kept for rollback."); + // The running broker holds auth in memory: restart so migrated tokens + // are recognized without waiting for the next natural restart. + const { stopBroker, ensureBroker } = await import("../broker/daemon.js"); + const wasRunning = (await import("../broker/daemon.js")).installationRuntime(); + if (wasRunning) { + await stopBroker(); + await new Promise((resolve) => setTimeout(resolve, 500)); + await ensureBroker(); + check("Broker restarted to load the migrated tokens"); + } } catch (error) { handleCliError(error, opts.json); }