fix: reconnect to a passwordless server without a token

The stored connection remembers that no password was set, but the
reconnect path still required a device token and asked for the password.
Reconnect without one when the server issued none.
This commit is contained in:
blumia committed 2026-11-16 10:41:04 +08:00
1 parent 23f72fc46d
commit ef0b63ceee
2 files changed
+23 -5

No files matched your search

+10 -5
View File
@@ -148,17 +148,22 @@ func (c *controller) connect() {
// reconnect retries a stored connection, whose token lives in secure // reconnect retries a stored connection, whose token lives in secure
// storage (readable only off the main thread). // storage (readable only off the main thread).
func (c *controller) reconnect(conn storage.Connection) { 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() { go func() {
token, ok, err := c.st.LoadToken(conn.URL) token, ok, err := c.st.LoadToken(conn.URL)
if err != nil || !ok { if err != nil || !ok {
ui.Post(func() { c.status.Set("请重新输入密码") }) ui.Post(func() { c.status.Set("请重新输入密码") })
return return
} }
params := connectParams{
url: conn.URL,
proxy: conn.Proxy,
insecure: conn.Insecure,
}
c.establish(params, token) c.establish(params, token)
}() }()
} }
+13
View File
@@ -221,3 +221,16 @@ func TestPasswordlessServer(t *testing.T) {
t.Errorf("passwordless not remembered: %+v", got) 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("请重新输入密码")
}