@@ -504,7 +504,7 @@ function buildOnboardArgs(payload) {
504504 "--gateway-token" ,
505505 OPENCLAW_GATEWAY_TOKEN ,
506506 "--flow" ,
507- payload . flow || "quickstart"
507+ payload . flow || "quickstart" ,
508508 ] ;
509509
510510 if ( payload . authChoice ) {
@@ -524,15 +524,25 @@ function buildOnboardArgs(payload) {
524524 "minimax-api" : "--minimax-api-key" ,
525525 "minimax-api-lightning" : "--minimax-api-key" ,
526526 "synthetic-api-key" : "--synthetic-api-key" ,
527- "opencode-zen" : "--opencode-zen-api-key"
527+ "opencode-zen" : "--opencode-zen-api-key" ,
528528 } ;
529+
529530 const flag = map [ payload . authChoice ] ;
530- if ( flag && secret ) {
531+
532+ // If the user picked an API-key auth choice but didn't provide a secret, fail fast.
533+ // Otherwise OpenClaw may fall back to its default auth choice, which looks like the
534+ // wizard "reverted" their selection.
535+ if ( flag && ! secret ) {
536+ throw new Error ( `Missing auth secret for authChoice=${ payload . authChoice } ` ) ;
537+ }
538+
539+ if ( flag ) {
531540 args . push ( flag , secret ) ;
532541 }
533542
534- if ( payload . authChoice === "token" && secret ) {
535- // This is the Anthropics setup-token flow.
543+ if ( payload . authChoice === "token" ) {
544+ // This is the Anthropic setup-token flow.
545+ if ( ! secret ) throw new Error ( "Missing auth secret for authChoice=token" ) ;
536546 args . push ( "--token-provider" , "anthropic" , "--token" , secret ) ;
537547 }
538548 }
@@ -571,12 +581,19 @@ app.post("/setup/api/run", requireSetupAuth, async (req, res) => {
571581 return res . json ( { ok : true , output : "Already configured.\nUse Reset setup if you want to rerun onboarding.\n" } ) ;
572582 }
573583
574- fs . mkdirSync ( STATE_DIR , { recursive : true } ) ;
575- fs . mkdirSync ( WORKSPACE_DIR , { recursive : true } ) ;
584+ fs . mkdirSync ( STATE_DIR , { recursive : true } ) ;
585+ fs . mkdirSync ( WORKSPACE_DIR , { recursive : true } ) ;
576586
577- const payload = req . body || { } ;
578- const onboardArgs = buildOnboardArgs ( payload ) ;
579- const onboard = await runCmd ( OPENCLAW_NODE , clawArgs ( onboardArgs ) ) ;
587+ const payload = req . body || { } ;
588+
589+ let onboardArgs ;
590+ try {
591+ onboardArgs = buildOnboardArgs ( payload ) ;
592+ } catch ( err ) {
593+ return res . status ( 400 ) . json ( { ok : false , output : `Setup input error: ${ String ( err ) } ` } ) ;
594+ }
595+
596+ const onboard = await runCmd ( OPENCLAW_NODE , clawArgs ( onboardArgs ) ) ;
580597
581598 let extra = "" ;
582599
0 commit comments