Skip to content

Commit 0d02025

Browse files
echobtfactorydroid
andauthored
fix(cortex-tui): auto-redirect to login on session expiration (#226)
When the user's session has expired (remaining hours == 0), automatically redirect them to the login screen instead of just showing a warning toast that says 'Run /login to authenticate'. This provides a better UX by removing the extra step of manually running /login when the session has already expired. Co-authored-by: Droid Agent <droid@factory.ai>
1 parent cc0b7d5 commit 0d02025

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

cortex-tui/src/runner/event_loop.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ impl EventLoop {
341341
// Initial render
342342
self.render(terminal)?;
343343

344-
// Check token expiration and warn user if expiring soon
345-
if let Ok(Some(auth)) = cortex_login::load_from_keyring() {
344+
// Check token expiration and handle accordingly
345+
let session_expired = if let Ok(Some(auth)) = cortex_login::load_from_keyring() {
346346
if auth.expires_soon(86400) {
347347
// 24 hours
348348
if let Some(remaining) = auth.time_until_expiry() {
@@ -352,13 +352,27 @@ impl EventLoop {
352352
"Session expires in {} hours. Run /login to refresh.",
353353
hours
354354
));
355+
false
355356
} else {
356-
self.app_state
357-
.toasts
358-
.warning("Session expired. Run /login to authenticate.");
357+
// Session already expired - will trigger login flow
358+
true
359359
}
360+
} else {
361+
false
360362
}
363+
} else {
364+
false
361365
}
366+
} else {
367+
false
368+
};
369+
370+
// If session is expired, automatically redirect to login page
371+
if session_expired {
372+
self.app_state
373+
.toasts
374+
.warning("Session expired. Redirecting to login...");
375+
self.start_login_flow().await;
362376
}
363377

364378
// Main event loop: poll BOTH FrameEngine events AND streaming events

0 commit comments

Comments
 (0)