fix: auto re-authenticate when token refresh fails#33
Conversation
Instead of throwing an error telling users to manually run `insforge login`, the CLI now automatically opens the OAuth login flow when a token refresh fails in interactive mode. Non-TTY environments still get the explicit error message. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/lib/credentials.ts`:
- Around line 70-76: The catch block around the token refresh in credentials.ts
is treating all errors as auth expiration and forcing interactive login; change
it to only trigger performOAuthLogin(apiUrl) when the error indicates an
authentication failure (e.g., HTTP 401/invalid_grant or an auth-specific error
code). In the catch for the refresh function (the code surrounding
performOAuthLogin and process.stdout.isTTY), inspect the caught error (e.g.,
error.response?.status === 401 or error.code/message matching invalid_grant) and
only call clack.log.warn and performOAuthLogin(apiUrl) in that case; for other
errors (network/timeouts/server 5xx) rethrow or return the error to the caller
so transient failures aren’t escalated to interactive login. Ensure you
reference the same symbols: the token refresh call, the catch block,
process.stdout.isTTY, and performOAuthLogin(apiUrl).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8741a9ed-4b16-4858-a82a-b65eb98fb7e7
📒 Files selected for processing (1)
src/lib/credentials.ts
Summary
insforge loginagain" messagenpx @insforge/cli createwith expired credentials would just error out instead of prompting loginTest plan
insforge createwith expired/invalid credentials — should auto-prompt OAuth login🤖 Generated with Claude Code
Note
Re-authenticate interactively when token refresh fails in
refreshAccessTokenWhen a token refresh fails in an interactive TTY session, credentials.ts now warns the user via
clack.log.warnand triggers an OAuth login flow instead of throwing anAuthError. Non-TTY environments preserve the existing behavior of throwing immediately.Macroscope summarized 8e6e338.
Summary by CodeRabbit