diff --git a/internal/control/control.go b/internal/control/control.go index e4fcdf6..a947311 100644 --- a/internal/control/control.go +++ b/internal/control/control.go @@ -39,6 +39,7 @@ type Manager struct { saved *hub.Saved stop context.CancelFunc username string + lastHub string // the hub last signed in to, for signing in again after signing out signin *signin } @@ -106,6 +107,9 @@ func (m *Manager) status() status { m.mu.Lock() defer m.mu.Unlock() s := status{Hub: m.DefaultHub} + if m.lastHub != "" { + s.Hub = m.lastHub + } if m.saved != nil { s.SignedIn, s.Hub, s.Username = true, m.saved.URL, m.username } @@ -118,7 +122,7 @@ func (m *Manager) status() status { // SignIn starts signing in to a hub; the code to enter shows in the status, and the browser opens the page. func (m *Manager) SignIn(hubURL string) { if hubURL == "" { - hubURL = m.DefaultHub + hubURL = m.status().Hub } ctx, cancel := context.WithCancel(context.Background()) si := &signin{running: true, cancel: cancel} @@ -159,6 +163,9 @@ func (m *Manager) SignIn(hubURL string) { func (m *Manager) SignOut() { m.mu.Lock() c, stop := m.client, m.stop + if m.saved != nil { + m.lastHub = m.saved.URL + } m.client, m.saved, m.stop, m.username, m.signin = nil, nil, nil, "", nil m.mu.Unlock() if c != nil { diff --git a/internal/control/control_test.go b/internal/control/control_test.go index 63661a1..60bccfa 100644 --- a/internal/control/control_test.go +++ b/internal/control/control_test.go @@ -109,6 +109,11 @@ func TestSignInAndOut(t *testing.T) { if _, err := os.Stat(path); !os.IsNotExist(err) { t.Fatalf("hub.json: %v", err) } + // Signing in again goes to the same hub. + m.DefaultHub = "https://elsewhere.test" + if s := ask(t, m, "GET", "/hub", ""); s.Hub != srv.URL { + t.Fatalf("hub after signing out: %q", s.Hub) + } // Only https hubs (or this computer's); other requests to the proxy's address are refused. u, _ := url.Parse("http://" + Host + "/hub/signin")