fix(cli): surface auth URL so headless logins can complete

Closed
JO
6mo ago
+30-4

Summary

Closes #3949.

superset auth login hangs on headless Linux hosts because openBrowser() invokes xdg-open via fire-and-forget exec() — when xdg-open is missing the failure is silent and no URL is ever surfaced.

Fix

  • Add an optional onAuthUrl(url) callback to a new LoginOptions interface in lib/auth.ts.
  • Refactor login(signal) → login(options). Single internal caller updated.
  • In the auth command, the callback prints the URL via p.log.info(...). On TTY clack interleaves it with the running spinner; on non-TTY it's a clean info line.

Browser auto-launch is unchanged for GUI users — openBrowser() is still invoked after the URL is surfaced.

Test plan

  • On macOS (TTY): browser still opens; URL also appears as a p.log.info line, interleaves cleanly with the spinner.
  • On Linux ARM64 headless (Hetzner Neoverse-N1, no xdg-open): URL is now printed. Combined with ssh -L 51789:localhost:51789 <host> the OAuth loopback callback completes through the tunnel and CLI logs in successfully.
  • bun run lint:fix && bun run typecheck — couldn't run locally; relying on CI.

Scope

  • packages/cli/src/lib/auth.ts — new LoginOptions; login() signature refactor; URL hoisted to a const; onAuthUrl invoked before openBrowser.
  • packages/cli/src/commands/auth/login/command.ts — pass options including the callback.

Out of scope (potential follow-ups)

  • openBrowser() still doesn't actually await exec() completion. Surfacing the URL eagerly sidesteps that for users; making openBrowser truly synchronous is a separate change.
  • A --no-browser flag for purely scripted flows.

Summary by cubic

Print the OAuth authorization URL during superset auth login so headless Linux hosts can complete login when no default browser is available. Auto-launch still works; this adds a visible URL fallback.

  • Bug Fixes
    • Added LoginOptions with optional onAuthUrl(url) and refactored login(signal) to login({ signal, ... }).
    • The auth command logs the URL before launching the browser, allowing copy/paste on headless hosts.
    • If an onAuthUrl callback throws, close the loopback server to avoid port leaks and “All loopback ports in use” errors.

Summary by CodeRabbit

  • Improvements
    • Enhanced authentication flow: the app now exposes a handler to surface the authorization URL and will print a fallback message with the URL during login if needed, improving visibility and reliability when completing sign-in from the browser.