Skip to content

fix(login): persist fresh credentials and drop the legacy auth file - #50

Merged
Taure merged 1 commit into
mainfrom
fix-asobi-cli-46
Aug 3, 2026
Merged

fix(login): persist fresh credentials and drop the legacy auth file#50
Taure merged 1 commit into
mainfrom
fix-asobi-cli-46

Conversation

@Taure

@Taure Taure commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Closes #46

credentialsPath() joined the result of os.UserHomeDir() with its error ignored. When the home directory cannot be resolved that yields the relative path .asobi/credentials.json, so asobi login wrote its tokens into whatever directory it was invoked from, printed "Login successful" and the hardcoded ~/.asobi/credentials.json, and left the previous credentials untouched - subsequent commands kept using the stale tokens and failed with invalid_refresh_token.

  • CredentialsPath() is now exported and returns an error instead of falling back to a relative path; load/save/delete propagate it.
  • cmdLogin resolves the path before starting the device-code flow, so an unusable environment fails immediately rather than after the user has approved the session.
  • SaveCredentials writes to a temp file in the target directory and renames it into place, so a failed write cannot leave a partial file or silently preserve the old tokens.
  • Login prints the actual path the credentials were written to.
  • The pre-credentials.json ~/.asobi/auth token file is removed on login and on logout, so an old binary still on PATH cannot resurrect expired tokens.

Tests cover re-login replacing stale tokens, the missing-home-dir failure (and that nothing is written to a relative .asobi/), and legacy-file removal being idempotent and leaving credentials.json intact.

Login resolved ~/.asobi/credentials.json by joining an ignored
os.UserHomeDir() error, so with no resolvable HOME it silently wrote to a
relative .asobi/ under the working directory while still reporting
success - stale tokens stayed in place and every later command failed
with invalid_refresh_token.

Resolve the path up front and fail before the device-code dance if it
cannot be determined, write the file atomically, print the real path, and
remove the pre-credentials.json ~/.asobi/auth token file on login and
logout.
@Taure
Taure merged commit 061598f into main Aug 3, 2026
1 check passed
@Taure
Taure deleted the fix-asobi-cli-46 branch August 3, 2026 09:39
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.

login prints success but writes no credential file (stale tokens keep being used)

1 participant