fix: harden auth flow and standardize CLI language#6
Conversation
This comment has been minimized.
This comment has been minimized.
|
This pull request introduces the use of the |
|
The pull request description does not contain a reference to a GitHub issue. Please edit the description to include a closing keyword like |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: abc4844508
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/commands/auth/team-key.ts
Outdated
| try { | ||
| await clearCredentials(); | ||
| } catch { | ||
| // Best effort cleanup. |
There was a problem hiding this comment.
Fail team-key setup when credential cleanup fails
getValidToken() now prefers stored user credentials over team keys, so swallowing errors from clearCredentials() can leave the old login token active while still printing a successful team-key authentication message. If credentials.json cannot be removed (for example due to file locking/permission issues), users think they switched modes but subsequent API calls continue using the stale bearer token.
Useful? React with 👍 / 👎.
This comment has been minimized.
This comment has been minimized.
|
This pull request does not seem to reference any issue. Please add a closing keyword like 'Closes #123' or 'Fixes #123' to the PR description to automatically link and close the relevant issue upon merging. Kody Rule violation: Ensure PR closes referenced issues |
This comment has been minimized.
This comment has been minimized.
|
The pull request description does not contain a reference to a GitHub issue. Please add a closing statement like 'Closes #123' or 'Fixes #123' to automatically link and close the relevant issue upon merging. Kody Rule violation: Ensure PR closes referenced issues |
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
|
The pull request description does not contain a reference to a GitHub issue (e.g., #123) or a closing keyword (e.g., 'Closes #123', 'Fixes #123'). Please update the description to link to the relevant issue. Kody Rule violation: Ensure PR closes referenced issues |
Summary
Key changes
Tests
This pull request significantly hardens the CLI's authentication flow and standardizes its language for improved reliability and user experience.
Key changes include:
Enhanced Authentication Reliability:
auth logoutcommand now removes both user login credentials and any configured team key, providing a complete local authentication reset.getValidTokenlogic has been refined to prioritize valid user access tokens. If an access token is expired, it attempts to refresh it; if the refresh fails, it gracefully falls back to a configured team key.auth logincommand now provides more informative prompts when a user is already authenticated, distinguishing between user account and team key sessions and offering clear options for switching.Self-Healing Configuration and Credentials:
config.jsonandcredentials.jsonusing temporary files and renames. This prevents file corruption if the CLI process crashes during a write operation.config.jsonandcredentials.jsonfiles (by renaming them to.corruptedfiles). This allows the CLI to recover gracefully from malformed data by treating it as if no configuration or credentials exist, preventing startup failures.Standardized CLI Language and Error Messages:
auth logoutdescription and other CLI output messages for clarity and consistency (e.g., "Not logged in" changed to "Not authenticated").git.service.tsfrom Portuguese to English.Robust API Interaction:
RealApicorrectly sends eitherAuthorization: Bearer(for user tokens) orX-Team-Key(for team keys) headers based on the authentication token type, improving API request accuracy.Expanded Test Coverage:
auth login,auth logout,auth team-key,auth team-status,AuthService,RealApiauthentication headers, and theconfigandcredentialsutility functions, validating the new behaviors and ensuring stability.