fix(auth): fail the login prompt when stdin ends without an answer by erikengervall · Pull Request #338 · firecrawl/cli · GitHub
Skip to content

fix(auth): fail the login prompt when stdin ends without an answer - #338

Merged
erikengervall merged 4 commits into
mainfrom
capy/fail-login-prompt-without-input
Oct 20, 2026
Merged

erikengervall merged 4 commits into
mainfrom
capy/fail-login-prompt-without-input

Conversation

@erikengervall

@erikengervall erikengervall commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

The login prompts read stdin with readline.question. When stdin ends before an answer (CI, coding agents, scripts, </dev/null), the callback never fires, the pending promise empties the event loop, and Node exits 0 right after printing Enter choice [1/2]:.

That hits two common paths:

  • firecrawl login without a terminal prints the menu and exits 0 with nothing saved.
  • firecrawl init --all (or -y) without --browser and without a key stops at step 1 and exits 0, so the skills step never runs and the caller sees success.

promptInput in src/utils/auth.ts now rejects when readline closes before an answer, with:

No input to log in with. Run "firecrawl login --browser", pass --api-key, or set FIRECRAWL_API_KEY.

Piped answers still work. Without a terminal, one line reader serves every prompt, so a pipe can answer several prompts in a row (printf '2\nfc-...\n' | firecrawl login), and a last answer without a trailing newline counts. Between prompts the reader pauses and unrefs stdin, so a pipe left open does not keep the process alive. Ctrl+C at the prompt still exits (130) instead of being treated as missing input. The callers already handle a rejected login: firecrawl login prints the error and exits 1, and init records the failed auth step, continues with the remaining steps, and exits 1 with "Setup incomplete: authentication failed".

Before and after, with an empty HOME and no FIRECRAWL_API_KEY:

$ firecrawl login </dev/null; echo $?
# before: login menu, then 0
# after:  the error above, then 1

$ firecrawl init --all --skip-install </dev/null; echo $?
# before: login menu, then 0, no skills installed
# after:  auth fails with the error above, skills install, then "Setup incomplete: authentication failed" and 1

This complements #328, which stops ensureAuthenticated() from reaching the menu without a terminal; this change covers login and init, which call the login flow directly. No version bump, so it ships with the next release.

Testing

  • New tests in src/__tests__/utils/auth.test.ts: the login menu and manual login reject when stdin ends without input, and a piped API key is still read, with or without a trailing newline, and successive prompts read successive piped lines. Both rejection tests time out without the fix.
  • pnpm test, pnpm type-check, pnpm format:check, pnpm build.

Found by Wildfire, Firecrawl's integration testing, while reproducing the failing cli-setup-mcp and cli-templates checks without a terminal.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Shadow auto-approve: would not auto-approve because issues were found.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread src/utils/auth.ts
Comment thread src/utils/auth.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files (changes from recent commits).

Shadow auto-approve: would not auto-approve because issues were found.

View guided diff | Turn on auto-fix | Re-trigger cubic

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/utils/auth.ts">

<violation number="1" location="src/utils/auth.ts:46">
P2: The EOF fallback resolves raw keystrokes in a TTY. If a user erases typed text (backspace or Ctrl+U) and then presses Ctrl+D, `unterminated` still holds the erased bytes, and `trim()` does not remove them. Limit the raw-stdin fallback to non-TTY input so an interactive EOF rejects instead.</violation>
</file>

Comment thread src/utils/auth.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Makes the login prompts reject when stdin ends without an answer, so firecrawl login/init no longer exit 0 mid-prompt; tests cover the new rejection and piped-key behavior. The fix is focused and pins the corrected behavior.

View guided diff | Turn on auto-fix | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Makes the login prompts reject when stdin ends without an answer, so firecrawl login/init no longer exit 0 mid-prompt; tests pin the new rejection and piped-input behavior. Focused, tested bug fix with no new exposure.

View guided diff | Turn on auto-fix | Re-trigger cubic

@erikengervall
erikengervall merged commit c8e63c7 into main Oct 20, 2026
8 checks passed
@erikengervall
erikengervall deleted the capy/fail-login-prompt-without-input branch October 20, 2026 04:21
erikengervall added a commit that referenced this pull request Oct 20, 2026
Squashed onto main 82229b1. The branch's merged-in work from #326, #336, #337, #338 and #339 is already on main; this commit holds only the Amp, Grok Build and Zed setup mcp change and the bump to 1.26.17.
erikengervall added a commit that referenced this pull request Oct 20, 2026
Squashed onto main 82229b1. The branch's merged-in work from #326, #336, #337, #338 and #339 is already on main; this commit holds only the Amp, Grok Build and Zed setup mcp change and the bump to 1.26.17.

Co-authored-by: erikengervall <5392475+erikengervall@users.noreply.github.com>
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