diff --git a/internal/appui/root.go b/internal/appui/root.go index 0745d17..b653321 100644 --- a/internal/appui/root.go +++ b/internal/appui/root.go @@ -148,17 +148,22 @@ func (c *controller) connect() { // reconnect retries a stored connection, whose token lives in secure // storage (readable only off the main thread). func (c *controller) reconnect(conn storage.Connection) { + params := connectParams{ + url: conn.URL, + proxy: conn.Proxy, + insecure: conn.Insecure, + } + if conn.Passwordless { + // No token was issued; the server answers without one. + go func() { c.establish(params, "") }() + return + } go func() { token, ok, err := c.st.LoadToken(conn.URL) if err != nil || !ok { ui.Post(func() { c.status.Set("请重新输入密码") }) return } - params := connectParams{ - url: conn.URL, - proxy: conn.Proxy, - insecure: conn.Insecure, - } c.establish(params, token) }() } diff --git a/internal/appui/root_test.go b/internal/appui/root_test.go index c735e15..c2b9220 100644 --- a/internal/appui/root_test.go +++ b/internal/appui/root_test.go @@ -221,3 +221,16 @@ func TestPasswordlessServer(t *testing.T) { t.Errorf("passwordless not remembered: %+v", got) } } + +func TestAutoReconnectPasswordlessWithoutToken(t *testing.T) { + srv := fakeServer(t, "", "") + t.Cleanup(srv.Close) + + st := &memStore{ + conn: storage.Connection{URL: srv.URL, Passwordless: true}, + has: true, + } + a := mount(t, st) + a.WaitFor("First session") + a.ExpectNo("请重新输入密码") +}