diff --git a/cmd/auth/login/login.go b/cmd/auth/login/login.go index ad3070e..42f012e 100644 --- a/cmd/auth/login/login.go +++ b/cmd/auth/login/login.go @@ -4,6 +4,7 @@ import ( "bufio" "errors" "fmt" + "io" "os" "strings" "time" @@ -33,6 +34,21 @@ func getDeviceName() string { return hostname } +func openBrowserQuietly(url string) error { + stdout := browser.Stdout + stderr := browser.Stderr + + browser.Stdout = io.Discard + browser.Stderr = io.Discard + + defer func() { + browser.Stdout = stdout + browser.Stderr = stderr + }() + + return browser.OpenURL(url) +} + func loginWithWeb(hostname string) (string, error) { // Build base URL for login (use hostname as-is, StartDeviceWebAuth will add /api/v1) baseURL := hostname @@ -81,7 +97,16 @@ func loginWithWeb(hostname string) (string, error) { _, err := reader.ReadString('\n') if err == nil { // User pressed Enter, open browser - if err := browser.OpenURL(loginURL); err != nil { + oldStdout := browser.Stdout + oldStderr := browser.Stderr + browser.Stdout = io.Discard + browser.Stderr = io.Discard + defer func() { + browser.Stdout = oldStdout + browser.Stderr = oldStderr + }() + + if err := openBrowserQuietly(loginURL); err != nil { // Don't fail if browser can't be opened, just warn logger.Warning("Failed to open browser automatically") logger.Info("Please manually visit: %s", baseLoginURL) @@ -328,11 +353,11 @@ func loginMain(cmd *cobra.Command, opts *LoginCmdOpts) error { } else if apiServerInfo != nil { // Convert api.ServerInfo to config.ServerInfo serverInfo := &config.ServerInfo{ - Version: apiServerInfo.Version, - SupporterStatusValid: apiServerInfo.SupporterStatusValid, - Build: apiServerInfo.Build, - EnterpriseLicenseValid: apiServerInfo.EnterpriseLicenseValid, - EnterpriseLicenseType: apiServerInfo.EnterpriseLicenseType, + Version: apiServerInfo.Version, + SupporterStatusValid: apiServerInfo.SupporterStatusValid, + Build: apiServerInfo.Build, + EnterpriseLicenseValid: apiServerInfo.EnterpriseLicenseValid, + EnterpriseLicenseType: apiServerInfo.EnterpriseLicenseType, } // Update account with server info account := accountStore.Accounts[user.UserID]