Skip to content
Open
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
28 changes: 22 additions & 6 deletions cmd/auth/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"errors"
"fmt"
"io"
"os"
"strings"
"time"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -81,7 +97,7 @@ 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 {
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)
Expand Down Expand Up @@ -328,11 +344,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]
Expand Down