Skip to content

[WIP] Fix logout functionality to remove token file#1900

Merged
lionello merged 4 commits intomainfrom
copilot/fix-defang-logout-issue
Feb 4, 2026
Merged

[WIP] Fix logout functionality to remove token file#1900
lionello merged 4 commits intomainfrom
copilot/fix-defang-logout-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

Fix "defang logout" to remove token file

Analysis Complete

  • Understand the issue: logout doesn't remove token file
  • Locate logout implementation in /src/pkg/cli/logout.go
  • Locate token file management in /src/pkg/cli/client/cluster.go
  • Identify that TODO comment exists at lines 18-22 in logout.go

Implementation Complete

  • Implement token file removal in logout function
  • Also remove JWT web identity token file if it exists
  • Fix logic bug: changed condition from if connect.CodeOf(err) != ... to if err != nil && connect.CodeOf(err) != ...
  • Add comprehensive tests for logout functionality
    • Test successful logout with token file removal
    • Test logout without token file (should not error)
    • Test logout with unauthenticated error (should still remove token)
  • Fix code style: remove trailing whitespace

Testing Complete

  • All unit tests pass
  • Manual testing confirms correct behavior

Security Checks Complete

  • CodeQL security checks: No alerts found

Summary

The defang logout command now properly removes the token file and JWT token file from the state directory. The implementation handles edge cases gracefully (missing files, unauthenticated errors) and includes comprehensive tests.

Original prompt

This section details on the original issue you should resolve

<issue_title>"defang logout" doesn't log me out</issue_title>
<issue_description>It doesn't actually remove the token file.</issue_description>

<agent_instructions>Login writes the token to a file in the state folder, but logout does not remove the file. </agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 3, 2026 21:48
Co-authored-by: lionello <591860+lionello@users.noreply.github.com>
Co-authored-by: lionello <591860+lionello@users.noreply.github.com>
@KevyVo
Copy link
Contributor

KevyVo commented Feb 4, 2026

@lionello I have a ran a test and it seem to be solid.

❯ defang whoami
 ! Provider account information not available: project name is required to load default stack

WORKSPACE  SUBSCRIBERTIER  NAME    EMAIL                   PROVIDER  REGION
KevyVo     PRO             KevyVo                                    us-west-2  
For help with warnings, check our FAQ at https://s.defang.io/warnings
 
defang/src on  copilot/fix-defang-logout-issue [$] via 🐹 v1.25.1 with 🐃 v1.60.0 via ❄️  impure (nix-shell-env) on ☁️  defang-sandbox (us-west-2) [X] on ☁️  kevin.vo@defang.io 
❯ defang logout
 * Successfully logged out

defang/src on  copilot/fix-defang-logout-issue [$] via 🐹 v1.25.1 with 🐃 v1.60.0 via ❄️  impure (nix-shell-env) on ☁️  defang-sandbox (us-west-2) [X] on ☁️  kevin.vo@defang.io 
❯ defang whoami
 ! Please log in to continue.
https://auth.defang.io/authorize?client_id=defang-cli&code_challenge=L8TRe5n2jI_HBeZfyjsq8ZmulGpYtryRNF0NU6T0Zbo&code_challenge_method=S256&redirect_uri=https%3A%2F%2Fauth.defang.io%2Fclients%2Fauth&response_type=code&state=9440c48a-0bef-485e-b9dd-f240042ee6c2
Please visit the above URL to log in. (Right click the URL or press ENTER to open browser)
 ! Provider account information not available: project name is required to load default stack

WORKSPACE  SUBSCRIBERTIER  NAME    EMAIL                   PROVIDER  REGION
KevyVo     PRO             KevyVo                                    us-west-2  
For help with warnings, check our FAQ at https://s.defang.io/warnings

I can see the token file is remove from my defang folder.

@KevyVo KevyVo marked this pull request as ready for review February 4, 2026 21:43
@lionello lionello enabled auto-merge (squash) February 4, 2026 21:45
@lionello lionello merged commit 7b5ee09 into main Feb 4, 2026
5 checks passed
@lionello lionello deleted the copilot/fix-defang-logout-issue branch February 4, 2026 21:55
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.

"defang logout" doesn't log me out

3 participants