π fix(auth): stop entering a session for a server that was never logged into - #50
Merged
Conversation
β¦ed into
Adding the very first server dropped straight onto the projects list without
ever asking for credentials.
`activeProfile` stands for an authenticated session β `RootView` presents
`MainView` as a full-screen cover the moment it turns non-nil. Two paths set it
without a token ever being stored:
- `addProfile` activated the profile whenever it was the first one, so the login
screen `AddServerView` pushed right after was covered before it could be seen.
`selectServer` already guarded against exactly this ("must not activate a
profile with no token"); the guard was simply missing here. Both login paths
call `setActiveProfile` on success, so activation on add was redundant too.
- `loadFromUserDefaults` fell back to `profiles.first` when no active profile was
stored. That resurrected the same bug one relaunch later, and it also undid
logging out: logout and "switch server" deliberately remove the stored key, so
the next launch walked straight back into the session the user had just left β
with no token at all in the logout case.
Activation now happens only where a token has been stored, and only an explicitly
saved profile is restored.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Reported from the first TestFlight build: adding the very first server lands on the projects list without ever asking for credentials.
Cause
activeProfilestands for an authenticated session βRootViewpresentsMainViewas a full-screen cover the moment it turns non-nil. Two places set it with no token stored.addProfileactivated the profile whenever it was the first one.AddServerViewdoes push the login screen right after, but the cover goes up first and buries it β which is why only the first server showed the bug; a second one logs in normally.selectServeralready carries the guard against precisely this ("Selecting must not activate a profile with no token, or the app would drop into a session it can't authenticate"); it was simply missing here. Both login paths callsetActiveProfileon success, so activating on add was redundant as well as harmful.loadFromUserDefaultsfell back toprofiles.firstwhen no active profile was stored. That brings the same bug back one relaunch later β and it quietly undid logging out. Logout and "switch server" both remove the stored key on purpose, so the next launch walked straight back into the session the user had just left; after a logout, with no token at all.Fix
Activation now happens only where a token has been stored, and only an explicitly saved profile is restored on launch.
Tests
159 passing (2 new). Four existing tests encoded the old behaviour and now activate explicitly, the way the login flow does:
addProfile appends without activating, even for the first profileβ invertedprofiles persist across instancesβ a saved-but-never-logged-into server no longer resumes a sessionan authenticated profile is restored on relaunchβ new, guards the legitimate caseclearing the active profile survives a relaunchβ new, covers the logout regressionswiftformat --lintclean on both files. Note the repo is formatted with 0.61.1 (as CI pins) while 0.62.1 locally flags ~37 pre-existing files β unrelated drift, untouched here.π€ Generated with Claude Code