Skip to content

Commit 352816f

Browse files
author
Brandon Evans
authored
Merge pull request #87 from RobotsAndPencils/auth-pref-ui-change
Show stored username in General preference pane even when we don't have a valid session
2 parents b27b0bf + 75457dd commit 352816f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Xcodes/Backend/AppState.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class AppState: ObservableObject {
180180
let username = Current.defaults.string(forKey: "username") {
181181
// remove any keychain password if we fail to log with an invalid username or password so it doesn't try again.
182182
try? Current.keychain.remove(username)
183+
Current.defaults.removeObject(forKey: "username")
183184
}
184185

185186
Logger.appState.error("Authentication error: \(error.legibleDescription)")

Xcodes/Frontend/Preferences/GeneralPreferencePane.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ struct GeneralPreferencePane: View {
1313
Preferences.Container(contentWidth: 400.0) {
1414
Preferences.Section(title: "Apple ID") {
1515
VStack(alignment: .leading) {
16-
if appState.authenticationState == .authenticated {
17-
Text(Current.defaults.string(forKey: "username") ?? "-")
16+
// If we have saved a username then we will show it here,
17+
// even if we don't have a valid session right now,
18+
// because we should be able to get a valid session if needed with the password in the keychain
19+
// and a 2FA code from the user.
20+
// Note that AppState.authenticationState is not necessarily .authenticated in this case, though.
21+
if let username = Current.defaults.string(forKey: "username") {
22+
Text(username)
1823
Button("Sign Out", action: appState.signOut)
1924
} else {
2025
Button("Sign In", action: { self.appState.presentingSignInAlert = true })

0 commit comments

Comments
 (0)