Skip to content

fix: clear stale auth state on re-login - #60

Merged
designcode merged 8 commits into
mainfrom
fix/auth-and-whoami
Apr 2, 2026
Merged

designcode merged 8 commits into
mainfrom
fix/auth-and-whoami

Conversation

@designcode

@designcode designcode commented Mar 31, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Allow OAuth re-login by removing the isAuthenticated() early-return block
  • On successful OAuth login, clear stale credentials.temporary from a previous credentials session
  • On successful credentials login, clear stale OAuth data (tokens, orgs, selectedOrg) from a previous OAuth session
  • credentials.saved (from tigris configure) is always preserved

Test plan

  • npm run build — clean
  • npm run test — 510 tests pass
  • npm run format && npm run lint:fix — clean
  • Manual: tigris login (OAuth), then tigris login --access-key ... --access-secret ... — verify OAuth state is cleared
  • Manual: tigris login --access-key ... --access-secret ..., then tigris login (OAuth) — verify temporary credentials are cleared
  • Manual: tigris configure, then re-login with either method — verify saved credentials persist

🤖 Generated with Claude Code


Note

Medium Risk
Touches core authentication/credential resolution and endpoint/env-var precedence, which can change how existing users are authenticated in different environments; mitigated by new unit tests but still broad behavioral impact.

Overview
Improves auth resolution and re-login behavior by making auth-method precedence explicit (AWS_PROFILE �� env vars �� stored login �� configured creds) via a new resolveAuthMethod() and updated getStorageConfig()/whoami flows.

Fixes stale session cross-contamination by clearing previous state on successful login: OAuth login now clears temporary credential sessions, and credentials login clears all OAuth tokens/org state; adds storage helpers (clearTemporaryCredentials, clearOAuthData) and tests covering the new priority ordering. Also updates lint/format scripts to include test/ and includes various test-only formatting/import cleanups.

Written by Cursor Bugbot for commit 81ee7fe. This will update automatically on new commits. Configure here.

designcode and others added 2 commits March 31, 2026 16:28
Extend lint, lint:fix, format, and format:check to cover test/**/*.ts
alongside src. Fix import ordering and formatting across all test files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Allow OAuth re-login (remove isAuthenticated block) and clear the
other method's temporary state when switching login methods to prevent
stale sessions from persisting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
designcode and others added 2 commits April 1, 2026 10:48
Add resolveAuthMethod() as a single source of truth for the auth
priority chain (AWS profile → OAuth → credentials login → env vars →
configured). Refactor getStorageConfig() to use it, and rewrite whoami
to display the active auth method with IAM identity for credential-based
methods.

Move getEnvCredentials, getEnvCredentialSource, and getCredentials from
storage.ts to provider.ts where they belong as auth resolution logic.

Add comprehensive tests for resolveAuthMethod() covering all 5 auth
methods, priority ordering, and edge cases (19 tests).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread src/auth/provider.ts Resolved
Single function now returns credentials with source field, eliminating
duplicated env var logic and the inconsistency flagged in PR review.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread src/lib/whoami.ts Resolved
designcode and others added 2 commits April 1, 2026 11:19
New priority: AWS profile → env vars → oauth → credentials → configured.
Env vars are explicit per-session overrides and should win over a
previously stored login.

Also replace unnecessary dynamic import of getStorageConfig in whoami
with the existing static import.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
AWS_ variables are the standard and should be checked before TIGRIS_
in getTigrisConfig() and getEnvCredentials().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread src/auth/storage.ts Resolved
When clearOAuthData() is called without first updating activeMethod,
resolveAuthMethod() would return oauth but no tokens exist, causing
getStorageConfig() to crash on authClient.getAccessToken().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@designcode
designcode merged commit 11cc183 into main Apr 2, 2026
5 checks passed
@designcode
designcode deleted the fix/auth-and-whoami branch April 2, 2026 10:00
@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 2.14.0-beta.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions

github-actions Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 2.15.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants