Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions codex-rs/tui_app_server/src/onboarding/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ impl AuthModeWidget {
.await
{
Ok(LoginAccountResponse::Chatgpt { login_id, auth_url }) => {
maybe_open_auth_url_in_browser(&request_handle, &auth_url);
*error.write().unwrap() = None;
*sign_in_state.write().unwrap() =
SignInState::ChatGptContinueInBrowser(ContinueInBrowserState {
Expand Down Expand Up @@ -880,6 +881,16 @@ impl WidgetRef for AuthModeWidget {
}
}

pub(super) fn maybe_open_auth_url_in_browser(request_handle: &AppServerRequestHandle, url: &str) {
if !matches!(request_handle, AppServerRequestHandle::InProcess(_)) {
return;
}

if let Err(err) = webbrowser::open(url) {
tracing::warn!("failed to open browser for login URL: {err}");
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use super::ContinueInBrowserState;
use super::ContinueWithDeviceCodeState;
use super::SignInState;
use super::mark_url_hyperlink;
use super::maybe_open_auth_url_in_browser;
use super::onboarding_request_id;

pub(super) fn start_headless_chatgpt_login(widget: &mut AuthModeWidget) {
Expand Down Expand Up @@ -289,6 +290,7 @@ async fn fallback_to_browser_login(
.await
{
Ok(LoginAccountResponse::Chatgpt { login_id, auth_url }) => {
maybe_open_auth_url_in_browser(&request_handle, &auth_url);
*error.write().unwrap() = None;
let _updated = set_device_code_state_for_active_attempt(
&sign_in_state,
Expand Down
Loading