Skip to content

Commit b4a1647

Browse files
echobtfactorydroid
andauthored
fix(cortex-tui): reload auth token into provider_manager after login (#231)
When a user re-authenticated after session expiration, the new token was saved to the keyring but never reloaded into the provider_manager. This caused subsequent API calls to fail with 'session invalid' because the provider_manager still had the old/expired token (or no token). The fix adds token reloading in two places in the ToolEvent::Completed handler for login events: - After 'login_poll' success (new interactive login flow) - After 'login' success (legacy chat-based login flow) This ensures that after any successful login, the fresh auth token is immediately available for API calls. Fixes: session invalid error after re-authentication Co-authored-by: Droid Agent <droid@factory.ai>
1 parent fded48b commit b4a1647

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

cortex-tui/src/runner/event_loop.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,6 +3012,42 @@ impl EventLoop {
30123012
// Login successful
30133013
self.app_state.login_flow = None;
30143014
self.app_state.exit_interactive_mode();
3015+
3016+
// CRITICAL: Reload fresh auth token into provider_manager
3017+
// Without this, the provider_manager still has the old/expired token
3018+
// and subsequent API calls will fail with "session invalid"
3019+
if let Some(ref pm) = self.provider_manager {
3020+
if let Some(token) = cortex_login::get_auth_token() {
3021+
tracing::info!(
3022+
"Reloading fresh auth token into provider_manager after login"
3023+
);
3024+
pm.write().await.set_auth_token(token);
3025+
} else {
3026+
tracing::warn!(
3027+
"Login succeeded but could not load fresh token from keyring"
3028+
);
3029+
}
3030+
}
3031+
3032+
self.app_state.toasts.success("Logged in!");
3033+
return;
3034+
} else if id == "login" && success {
3035+
// Legacy login flow (from handle_auth_login) - also reload the token
3036+
// CRITICAL: Reload fresh auth token into provider_manager
3037+
// Without this, the provider_manager still has the old/expired token
3038+
if let Some(ref pm) = self.provider_manager {
3039+
if let Some(token) = cortex_login::get_auth_token() {
3040+
tracing::info!(
3041+
"Reloading fresh auth token into provider_manager after legacy login"
3042+
);
3043+
pm.write().await.set_auth_token(token);
3044+
} else {
3045+
tracing::warn!(
3046+
"Login succeeded but could not load fresh token from keyring"
3047+
);
3048+
}
3049+
}
3050+
self.add_system_message(&output);
30153051
self.app_state.toasts.success("Logged in!");
30163052
return;
30173053
}

0 commit comments

Comments
 (0)