From 1e92db25f08a65594e461218c3ff061f6b5837b8 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Tue, 1 Sep 2026 23:38:50 +0200 Subject: [PATCH] Name the login a row is actually holding Signing in again as somebody else left the row naming the previous person while the app had already switched to serving the new one's data. The identifier lives in the Keychain beside the secret, so nothing SwiftUI watches moves: same account, same context, and the status was already signed-in. The credential change is announced, so the section listens for it and re-reads what it displays. On one instance the identifier is the only thing telling two logins apart, which makes naming the wrong one worse than showing no name at all. --- .../Settings/InstanceAccountsSection.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Yattee/Views/Settings/InstanceAccountsSection.swift b/Yattee/Views/Settings/InstanceAccountsSection.swift index bfdd9631..dffe763a 100644 --- a/Yattee/Views/Settings/InstanceAccountsSection.swift +++ b/Yattee/Views/Settings/InstanceAccountsSection.swift @@ -28,6 +28,18 @@ struct InstanceAccountsSection: View { @Environment(\.appEnvironment) private var appEnvironment + /// Bumped whenever a credential is replaced, purely to re-read the login + /// identifier the rows display. + /// + /// That identifier lives in the Keychain beside the secret, not in any + /// observable state, so signing in again as somebody else moves nothing + /// SwiftUI watches — same account, same context, and the status was + /// already `signedIn`. Without this the row keeps naming the previous + /// person while the app is already serving the new one's data, which is + /// exactly backwards: the label is the only thing telling two logins on + /// one instance apart. + @State private var credentialRevision = 0 + private var accounts: [Account] { appEnvironment?.accountsManager.accounts(forInstance: instance.id) ?? [] } @@ -37,6 +49,10 @@ struct InstanceAccountsSection: View { ForEach(accounts) { account in accountRow(account) } + // Read here on purpose, so the rows genuinely depend on it rather + // than relying on a state write invalidating a body that never + // mentions it. + .id(credentialRevision) Button { loginTarget = .newAccount @@ -54,6 +70,9 @@ struct InstanceAccountsSection: View { } footer: { Text(String(localized: accounts.isEmpty ? "login.footer.loginBenefits" : "login.footer.loggedIn")) } + .onReceive(NotificationCenter.default.publisher(for: .accountCredentialDidChange)) { _ in + credentialRevision &+= 1 + } } // MARK: - Rows