Skip to content

fix(auth): retry a failed revoke and sign out a running TUI - #12

Merged
mr-karan merged 1 commit into
mainfrom
fix/auth-logout-retry
Nov 16, 2026
Merged

mr-karan merged 1 commit into
mainfrom
fix/auth-logout-retry

Conversation

@mr-karan

Copy link
Copy Markdown
Member

Why

kite auth logout should end the session on Kite, or say plainly that it has not. Closes #10: after an offline logout the CLI discarded the only copy of the token, so it could never be revoked. A second logout printed "nothing to revoke" while the session was still live, and an open TUI kept trading on it.

This takes options A and C from the issue.

What changed

  • Retry (A). Logout drops a token only once Kite confirms the session ended: a successful revoke, or a TokenException saying it is already invalid. Any other failure keeps the token in a new revoke_pending config field. The next logout retries it and reports Revoked 1 session on Kite from an earlier logout, or warns that it is still active. Tokens expire at 6 AM IST, after which Kite answers TokenException, so the list cannot grow without bound.
  • Running TUI (C). The TUI checks the saved token every 2 seconds. If a logout cleared it, the TUI returns to the sign-in screen ("Signed out with kite auth logout"). If a login in another terminal replaced it, the TUI restarts on the new session. Sessions started from KITE_ACCESS_TOKEN are not watched.
  • TUI logout. Logging out from inside the TUI used to remove the local token without revoking it. It now goes through the same app::logout::end_session as kite auth logout, and its confirm modal says it revokes.

Reviewer notes

  • auth logout --json gains earlier_revoked and revoke_pending. revoked keeps its meaning for the current session.
  • revoke_pending holds live tokens, so it gets the same protection as access_token. It is written with the existing private file mode and redacted from Debug, which a test checks.
  • A config with no API root or key used to drop the token after a failed revoke. It now keeps the token pending, so it can still be revoked once the config is fixed.

Verification

  • An integration test runs the issue's scenario through the binary. A logout against a failing Kite keeps the token pending. The next logout revokes it, and a third reports nothing to revoke.
  • Another integration test checks that a pending token Kite answers with TokenException is dropped.
  • A unit test checks that the watcher reports a cleared or replaced token and stays quiet while it is unchanged.
  • A TUI loop test checks that each change ends the session with the right exit.
  • cargo clippy -D warnings and the full cargo test pass locally.

Not checked by hand: a real offline logout against a running TUI on a live account.

An offline `kite auth logout` removed the only copy of the token, so it
could never be revoked: a second logout printed "nothing to revoke"
while the session was still live on Kite, and a TUI that was already
open kept using it.

Logout now drops a token only once Kite confirms the session ended,
either by revoking it or by rejecting it as already invalid. A token it
cannot revoke is kept in revoke_pending, and the next logout retries it
and reports the result. The TUI's own logout goes through the same path;
before, it removed the local token without revoking it at all.

A running TUI watches the saved token. When a logout clears it the TUI
returns to the sign-in screen, and when a new login replaces it the TUI
restarts on the new session.

Closes #10
@mr-karan
mr-karan force-pushed the fix/auth-logout-retry branch from 161a48f to 81d7a0b Compare November 16, 2026 08:46
@mr-karan
mr-karan merged commit f61ecc1 into main Nov 16, 2026
3 checks passed
@mr-karan
mr-karan deleted the fix/auth-logout-retry branch November 16, 2026 08:49
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.

Auth logout: after an offline logout the token can no longer be revoked, and a running TUI stays signed in

1 participant