mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-20 21:23:23 +00:00
Fix onboard ignoring OPENCLAW_GATEWAY_TOKEN env var (#22658)
* Fix onboard ignoring OPENCLAW_GATEWAY_TOKEN env var When running onboard via docker-setup.sh, the QuickStart wizard generates its own 48-char token instead of using the 64-char token already set in OPENCLAW_GATEWAY_TOKEN. This causes a token mismatch that breaks all CLI commands after setup. Check process.env.OPENCLAW_GATEWAY_TOKEN before falling back to randomToken() in both the interactive QuickStart path and the non-interactive path. Closes #22638 Co-authored-by: Clawborn <tianrun.yang103@gmail.com> * Tests: cover quickstart env token fallback * Changelog: note docker onboarding token parity fix * Tests: restore env var after non-interactive token fallback test * Update CHANGELOG.md --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
@@ -88,6 +88,40 @@ describe("configureGatewayForOnboarding", () => {
|
||||
"reminders.add",
|
||||
]);
|
||||
});
|
||||
|
||||
it("prefers OPENCLAW_GATEWAY_TOKEN during quickstart token setup", async () => {
|
||||
const prevToken = process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||
process.env.OPENCLAW_GATEWAY_TOKEN = "token-from-env";
|
||||
mocks.randomToken.mockReturnValue("generated-token");
|
||||
mocks.randomToken.mockClear();
|
||||
|
||||
const prompter = createPrompter({
|
||||
selectQueue: ["loopback", "token", "off"],
|
||||
textQueue: [],
|
||||
});
|
||||
const runtime = createRuntime();
|
||||
|
||||
try {
|
||||
const result = await configureGatewayForOnboarding({
|
||||
flow: "quickstart",
|
||||
baseConfig: {},
|
||||
nextConfig: {},
|
||||
localPort: 18789,
|
||||
quickstartGateway: createQuickstartGateway("token"),
|
||||
prompter,
|
||||
runtime,
|
||||
});
|
||||
|
||||
expect(result.settings.gatewayToken).toBe("token-from-env");
|
||||
} finally {
|
||||
if (prevToken === undefined) {
|
||||
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||
} else {
|
||||
process.env.OPENCLAW_GATEWAY_TOKEN = prevToken;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("does not set password to literal 'undefined' when prompt returns undefined", async () => {
|
||||
mocks.randomToken.mockReturnValue("unused");
|
||||
|
||||
|
||||
@@ -161,12 +161,18 @@ export async function configureGatewayForOnboarding(
|
||||
let gatewayToken: string | undefined;
|
||||
if (authMode === "token") {
|
||||
if (flow === "quickstart") {
|
||||
gatewayToken = quickstartGateway.token ?? randomToken();
|
||||
gatewayToken =
|
||||
(quickstartGateway.token ??
|
||||
normalizeGatewayTokenInput(process.env.OPENCLAW_GATEWAY_TOKEN)) ||
|
||||
randomToken();
|
||||
} else {
|
||||
const tokenInput = await prompter.text({
|
||||
message: "Gateway token (blank to generate)",
|
||||
placeholder: "Needed for multi-machine or non-loopback access",
|
||||
initialValue: quickstartGateway.token ?? "",
|
||||
initialValue:
|
||||
quickstartGateway.token ??
|
||||
normalizeGatewayTokenInput(process.env.OPENCLAW_GATEWAY_TOKEN) ??
|
||||
"",
|
||||
});
|
||||
gatewayToken = normalizeGatewayTokenInput(tokenInput) || randomToken();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user