Skip to content

fix(auth): keep the browser open for interactive sign-in - #24

Merged
marcinobel merged 1 commit into
developfrom
fix/auth-interactive-signin
Sep 18, 2026
Merged

marcinobel merged 1 commit into
developfrom
fix/auth-interactive-signin

Conversation

@marcinobel

Copy link
Copy Markdown
Member

revcli auth closed the browser window as soon as Google Maps rendered, so it could never be used to sign in. The cause was an early return in authLoginCommand:

if (await isSignedIn(page)) {
  logger.success("Already signed in to Google Maps. No action needed.");
  return;   // -> finally { closeBrowser() }
}

Whenever the profile already held a session, the command declared "no action needed" about 4s after the map painted and shut the window — leaving revcli auth logout followed by revcli auth as the only way to sign in or switch accounts. That is backwards for the one command whose job is credential entry.

Changes

  • src/commands/auth.ts — the early return is gone. The window now stays open either way: for credential entry when signed out, and for account switching when signed in. It closes when sign-in is detected, or when the user closes it.
  • src/scraper/auth.ts — waitForSignIn() returns SignInOutcome ("signed-in" | "browser-closed") instead of void, so each caller states its closed-window policy: fatal for waitForUserAuth(), because a scrape cannot continue without a session, but a normal end for auth. New waitForBrowserClose() covers the signed-in case, polling pages() as well as the context close event — closing the last window on macOS leaves the process, and therefore the context, alive.
  • tests/auth.test.ts — 10 new cases (287 → 297) pinning both end states of each waiter. waitForBrowserClose() takes the narrow structural ClosableBrowser rather than a BrowserContext, so it is testable against a fake with no browser.
  • AGENTS.md, README.md, CHANGELOG.md — the test count, the auth-flow description, and the documented auth behaviour.

Also fixed

The 5-minute timeout threw out of an async Commander action. program.parse() does not await action handlers, so it surfaced as an unhandled rejection with a raw stack trace. It now reports the timeout and exits 1 cleanly.

Verified

  • Reproduced on the installed 0.1.4 before the fix: revcli auth printed "Already signed in to Google Maps. No action needed." and closed 4s after the map loaded.
  • After the fix, on the real command: still running after 12s; the CLI exited ~2s after the window was closed, logging ✔ Browser closed. Google session saved for later runs. with exit code 0 and no stack trace.
  • The signed-out path was exercised in a throwaway profile: the browser stays open and polls, so the wait loop itself was never the problem.
  • npm run typecheck, npm test (297 passed), npm run build, npm run check:pack, npm run test:package — all green locally.

Note

This machine's profile already holds a valid session (cookies good to 2027-10-22), so revcli auth now opens the window and waits to be closed; switching accounts means signing out inside that window first.

`revcli auth` closed the window as soon as Google Maps rendered whenever
the profile already held a Google session — "already signed in, no action
needed" — which made the one command whose job is credential entry
useless for signing in or switching accounts. The only way through was
`revcli auth logout` first.

The window now stays open either way: for credential entry when signed
out, and for account switching when signed in. It closes when sign-in is
detected or when the user closes it.

`waitForSignIn()` returns `SignInOutcome` ("signed-in" | "browser-closed")
instead of `void`, so each caller can treat a closed window differently:
fatal for a scrape, which cannot continue without a session, but a normal
end for `auth`. `waitForBrowserClose()` covers the signed-in case, polling
`pages()` as well as the context `close` event because closing the last
window on macOS leaves the process alive.

Also fixed while in the flow: the 5-minute timeout threw out of an async
Commander action, which `program.parse()` does not await, so it surfaced
as an unhandled rejection with a raw stack trace. It now reports the
timeout and exits 1.

Verified on the real command: the window stayed open past 12s where it
previously closed after ~4s, and the CLI exited cleanly ~2s after the
window was closed. 10 new tests in tests/auth.test.ts (287 -> 297) pin
both end states of each waiter; AGENTS.md, README and CHANGELOG updated.
@marcinobel
marcinobel merged commit f7b306b into develop Sep 18, 2026
1 check passed
@marcinobel
marcinobel deleted the fix/auth-interactive-signin branch September 18, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant