fix(auth): unify first-run setup into one browser handoff (BUG-1843) - #739
Merged
Conversation
On a fresh instance, `pad init` / `pad auth setup` created the admin account in the browser and dropped the operator on the console, then printed a SECOND "authorize the CLI" URL back in the terminal that a user who'd moved to the browser never saw — forcing a ctrl-C + re-run. Collapse it into a single browser tab: the CLI mints the pending CLI auth session up front and hands /setup a validated `next=/auth/cli/<code>` target, so account creation flows straight into the approval page where the just-bootstrapped admin approves in one click and the CLI connects. - internal/cli/bootstrap.go: thread `next` into the /setup URL (query before the #token fragment); raise bootstrapPollTimeout to 20m to match the setup session TTL. - cmd/pad/main.go: extract pollAndSaveCLIAuth; runBrowserSetup pre-creates the session and polls it; `pad workspace init` drives local setup inline. - cmd/pad/init.go: `pad init` routes through the unified handoff. - internal/store + internal/server: grant a setup-specific 20m CLI auth session TTL when UserCount==0 so the combined create-account + approve window can't expire mid-flow; normal logins keep the 5m default. - web/src/routes/setup: honor a validated local `next` redirect (open- redirect guarded), preserved across the token-fragment scrub. Reviewed via Codex loop (3 rounds → clean). Claude-Session: https://claude.ai/code/session_01KmxkPxLksjf1pmrZDpsnTJ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem (BUG-1843)
On a fresh, locally-hosted instance, first-run setup was two disconnected browser handoffs. The operator opened the
/setuplink, created the admin account, and the page dropped them on the console — while the CLI only then printed a second "authorize the CLI" URL back in the terminal, which a user who'd moved to the browser never saw. The result: ctrl-C out of the wedgedpad init, re-run, and only the second run reached the approval page.Fix — one browser handoff
The CLI mints the pending CLI auth session up front and hands
/setupa validatednext=/auth/cli/<code>target. Account creation now flows straight into the approval page (where the just-bootstrapped admin is already authenticated), one click finishes login, and the CLI polls that pre-created session and connects. No return-to-terminal gap.internal/cli/bootstrap.go— threadnextinto the/setupURL (query before the#tokenfragment, URL-escaped); raisebootstrapPollTimeoutto 20m to match the setup session TTL.cmd/pad/main.go— extractpollAndSaveCLIAuth;runBrowserSetuppre-creates the session and polls it;pad workspace initdrives local setup inline instead of erroring.cmd/pad/init.go—pad initroutes through the unified handoff.internal/store+internal/server— grant a setup-specific 20m CLI auth session TTL whenUserCount()==0so the combined create-account + approve window can't expire mid-flow; normalpad auth loginkeeps the 5m default.web/src/routes/setup/+page.svelte— honor a validated localnextredirect (open-redirect guarded), preserved across the token-fragment scrub.Verification
next-before-#tokenURL ordering.internal/cli/cmd/pad/internal/store/internal/serversuites pass; web build clean.https://claude.ai/code/session_01KmxkPxLksjf1pmrZDpsnTJ