Skip to content

Commit be57e18

Browse files
committed
fix(cortex-tui): remove expired token to prevent 'Already Logged In' dialog
When a session expires, the credentials remain in storage which causes the 'Already Logged In' dialog to appear incorrectly. This fix ensures that expired credentials are deleted when detected, so users won't be treated as logged in when their session has actually expired. Changes: - In start_login_flow: Delete stale credentials when session is expired - In run_direct_provider: Delete stale credentials on token expiration - In run_direct_provider: Delete invalidated credentials when server rejects the authentication Fixes the issue where users see 'Already Logged In' even though their session has expired.
1 parent 0d02025 commit be57e18

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

cortex-tui/src/runner/app_runner.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use crate::session::CortexSession;
5252

5353
use anyhow::Result;
5454
use cortex_engine::Config;
55-
use cortex_login::{CredentialsStoreMode, load_auth};
55+
use cortex_login::{CredentialsStoreMode, load_auth, logout_with_fallback};
5656
use cortex_protocol::ConversationId;
5757
use std::path::PathBuf;
5858
use tracing;
@@ -487,7 +487,11 @@ impl AppRunner {
487487
AuthStatus::Authenticated
488488
}
489489
Ok(Some(_)) => {
490-
// Token expired
490+
// Token expired - delete stale credentials so user doesn't appear as "logged in"
491+
tracing::info!("Token expired, removing stale credentials");
492+
if let Err(e) = logout_with_fallback(&cortex_home) {
493+
tracing::warn!("Failed to remove expired credentials: {}", e);
494+
}
491495
AuthStatus::Expired
492496
}
493497
Ok(None) => {
@@ -524,6 +528,10 @@ impl AppRunner {
524528
tracing::warn!(
525529
"Server rejected authentication - session may have been revoked"
526530
);
531+
// Delete the invalidated credentials
532+
if let Err(e) = logout_with_fallback(&cortex_home) {
533+
tracing::warn!("Failed to remove invalidated credentials: {}", e);
534+
}
527535
auth_status = AuthStatus::Expired;
528536
}
529537
Err(e) => {

cortex-tui/src/runner/event_loop.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4692,7 +4692,7 @@ impl EventLoop {
46924692
use crate::interactive::builders::{
46934693
LoginFlowState, build_already_logged_in_selector, build_login_selector,
46944694
};
4695-
use cortex_login::{CredentialsStoreMode, load_auth};
4695+
use cortex_login::{CredentialsStoreMode, load_auth, logout_with_fallback};
46964696

46974697
// Get cortex home directory
46984698
let cortex_home = match dirs::home_dir() {
@@ -4709,6 +4709,12 @@ impl EventLoop {
47094709
let interactive = build_already_logged_in_selector();
47104710
self.app_state.enter_interactive_mode(interactive);
47114711
return;
4712+
} else {
4713+
// Session is expired - delete the expired token so user won't appear as "logged in"
4714+
tracing::info!("Detected expired session, removing stale credentials");
4715+
if let Err(e) = logout_with_fallback(&cortex_home) {
4716+
tracing::warn!("Failed to remove expired credentials: {}", e);
4717+
}
47124718
}
47134719
}
47144720

0 commit comments

Comments
 (0)