fix(auth): make logout reject only the credential tea stored

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-18 17:14:46 +02:00
1 parent d67963b29a
commit 45e015e7dc
6 files changed
+50 -28

No files matched your search

+10 -4
View File
@@ -98,10 +98,11 @@ func (m Manager) register(instance, user string, account settings.Account, optio
})
}
// Logout removes one account and restores its credential if publication fails.
// An unreadable credential does not prevent removing the account.
func (m Manager) Logout(instance, user string) error {
return m.settings.Transaction(settings.TargetHosts, func(s *settings.Snapshot) (func() error, error) {
// Logout removes one account, restores its credential if publication fails and returns the
// removed credential. An unreadable credential does not prevent removing the account.
func (m Manager) Logout(instance, user string) (Credential, error) {
var removed Credential
err := m.settings.Transaction(settings.TargetHosts, func(s *settings.Snapshot) (func() error, error) {
host := s.Hosts.Hosts[instance]
account, exists := host.Users[user]
if !exists {
@@ -111,6 +112,7 @@ func (m Manager) Logout(instance, user string) error {
if !account.Tokenless() {
credential, err := m.credentials.Load(instance, user, account.CredentialStore)
if err == nil {
removed = credential
// Preserve a compensating copy until the account file is successfully published.
restore = func() error { return m.credentials.Save(instance, user, account.CredentialStore, credential) }
}
@@ -132,4 +134,8 @@ func (m Manager) Logout(instance, user string) error {
s.Hosts.Hosts[instance] = host
return restore, nil
})
if err != nil {
return Credential{}, err
}
return removed, nil
}