Show stored username in General preference pane even when we don't have a valid session #87
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This reverts the change from 90c0679 (in #45) so that the username is shown in situations where we don't have a valid session but could almost certainly get one. Instead, to achieve what that commit was trying to do (not appear signed in when auth failed), we'll instead remove the username from UserDefaults if auth fails with an invalid username or password error. I think this will more closely match what users expect in this UI.
I've added a comment in the UI explaining why it is the way it is. It might also be worth considering renaming AuthenticationState or its cases to better reflect that it's probably more about the (short-lived) session state than whether the user has signed in before and has stored their credentials.
Testing
Run the app on
main
Sign in in Preferences > General
Re-run the app
Open Preferences > General and see that it appears as if you're not signed in
Run the app on this branch
Sign in in Preferences > General
Re-run the app
Open Preferences > General and see that it appears as if you are signed in
Verify that auth still works by installing an Xcode or refreshing data while using the Apple data source. In either case you should at most be prompted to enter a 2FA code, and it shouldn't fail with an auth error.