Skip to content

fix: Login command - trim keys/profiles, handle write errors and clear messages#101

Open
Shubhdeep12 wants to merge 4 commits intoresend:mainfrom
Shubhdeep12:fix/login-command
Open

fix: Login command - trim keys/profiles, handle write errors and clear messages#101
Shubhdeep12 wants to merge 4 commits intoresend:mainfrom
Shubhdeep12:fix/login-command

Conversation

@Shubhdeep12
Copy link
Contributor

@Shubhdeep12 Shubhdeep12 commented Mar 14, 2026

  • trim API key and profile input.
  • to show a readable source when an existing key is found
  • Ask before overwriting an existing profile name
  • Add profile to JSON success and document new error codes
  • to use shared getCredentialsPath() in logout
  • added test

Summary by cubic

Improves the login UX and reliability: trims and validates keys and profile names, confirms overwrites, and returns clearer errors and JSON. Logout now uses the shared credentials path.

  • New Features

    • Trim API key and --profile inputs; reject empty/whitespace.
    • Validate profile names; prompt to name if missing, rename if invalid, and confirm before overwriting.
    • Auto-switch only when --profile is provided; otherwise keep the current active profile.
    • JSON success output now includes profile.
    • Show human-readable source for existing keys (command line --api-key, environment, saved).
    • Added error codes: invalid_profile_name, switch_failed, write_failed.
  • Bug Fixes

    • Handle credential file write failures and exit cleanly.
    • Return invalid_key_format for non-re_ keys; validation_failed when the API rejects a key.
    • Use shared getCredentialsPath() in logout for consistent file resolution.
    • Correctly pass --api-key to existing key detection so the right source is shown.

Written for commit ed260e3. Summary will update on new commits.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

1 issue found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tests/commands/auth/login.test.ts">

<violation number="1" location="tests/commands/auth/login.test.ts:62">
P2: Test mocks Resend SDK error with rejection pattern (mockRejectedValueOnce), but SDK uses { data, error } return pattern for API failures - test may exercise wrong error handling path</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@Shubhdeep12
Copy link
Contributor Author

hey @felipefreitag any thoughts here?

} else {
profileName = 'default';
const newName = await p.text({
message: 'Enter a name for this profile:',
Copy link
Contributor

@felipefreitag felipefreitag Mar 18, 2026

Choose a reason for hiding this comment

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

This adds friction to the first login; can you please revert this?

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.

2 participants