Skip to content

Commit a625093

Browse files
committed
codex: cancel stale device-code login attempts (#16827)
1 parent bc93d8b commit a625093

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

codex-rs/tui/src/onboarding/auth.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ fn onboarding_request_id() -> codex_app_server_protocol::RequestId {
105105
codex_app_server_protocol::RequestId::String(Uuid::new_v4().to_string())
106106
}
107107

108+
pub(super) async fn cancel_login_attempt(
109+
request_handle: &AppServerRequestHandle,
110+
login_id: String,
111+
) {
112+
let _ = request_handle
113+
.request_typed::<codex_app_server_protocol::CancelLoginAccountResponse>(
114+
ClientRequest::CancelLoginAccount {
115+
request_id: onboarding_request_id(),
116+
params: CancelLoginAccountParams { login_id },
117+
},
118+
)
119+
.await;
120+
}
121+
108122
#[derive(Clone, Default)]
109123
pub(crate) struct ApiKeyInputState {
110124
value: String,
@@ -245,28 +259,14 @@ impl AuthModeWidget {
245259
let request_handle = self.app_server_request_handle.clone();
246260
let login_id = state.login_id.clone();
247261
tokio::spawn(async move {
248-
let _ = request_handle
249-
.request_typed::<codex_app_server_protocol::CancelLoginAccountResponse>(
250-
ClientRequest::CancelLoginAccount {
251-
request_id: onboarding_request_id(),
252-
params: CancelLoginAccountParams { login_id },
253-
},
254-
)
255-
.await;
262+
cancel_login_attempt(&request_handle, login_id).await;
256263
});
257264
}
258265
SignInState::ChatGptDeviceCode(state) => {
259266
if let Some(login_id) = state.login_id().map(str::to_owned) {
260267
let request_handle = self.app_server_request_handle.clone();
261268
tokio::spawn(async move {
262-
let _ = request_handle
263-
.request_typed::<codex_app_server_protocol::CancelLoginAccountResponse>(
264-
ClientRequest::CancelLoginAccount {
265-
request_id: onboarding_request_id(),
266-
params: CancelLoginAccountParams { login_id },
267-
},
268-
)
269-
.await;
269+
cancel_login_attempt(&request_handle, login_id).await;
270270
});
271271
}
272272
}

codex-rs/tui/src/onboarding/auth/headless_chatgpt_login.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::shimmer::shimmer_spans;
1515
use super::AuthModeWidget;
1616
use super::ContinueWithDeviceCodeState;
1717
use super::SignInState;
18+
use super::cancel_login_attempt;
1819
use super::mark_url_hyperlink;
1920
use super::onboarding_request_id;
2021

@@ -47,13 +48,15 @@ pub(super) fn start_headless_chatgpt_login(widget: &mut AuthModeWidget) {
4748
&request_id,
4849
ContinueWithDeviceCodeState::ready(
4950
request_id.clone(),
50-
login_id,
51+
login_id.clone(),
5152
verification_url,
5253
user_code,
5354
),
5455
);
5556
if updated {
5657
*error.write().unwrap() = None;
58+
} else {
59+
cancel_login_attempt(&request_handle, login_id).await;
5760
}
5861
}
5962
Ok(other) => {

0 commit comments

Comments
 (0)