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.
This commit is contained in:
Arkadiusz Fal
2026-09-01 23:38:50 +02:00
parent 012e252641
commit 1e92db25f0

View File

@@ -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