[PR #106] Customer App Task 3: Keeping the Login After the App Restarts
I requested this work.
- What was done: For the third customer app task, the login now survives closing and reopening the app. The refresh key (the key used to get a new access token) is kept only in secure storage, and the access token (the temporary proof attached to requests) only in memory. When the app starts, it goes to the login screen if there is no refresh key, and gets a new access token if there is one. On a network failure or a server error it leaves the key alone and shows a “try again” screen. If the server answers that the access token has expired (401), the app refreshes once and resends the same request. If a suspended or withdrawn response arrives, it goes to the matching notice screen. The screens are text-only placeholders.
- Chosen approach:
- The notice that a session ended goes through one global handler in the client. Passing session information into every request would have meant changing every caller, so that was dropped.
- If several requests expire at the same time, only one refresh runs and the others wait for it.
- The test tool picked up the wrong React version and could not run, so the settings pin it to the app’s React version. Upgrading the tool’s version would have disagreed with the app, so that was dropped.
- The splash screen uses the one the existing router already exports, without installing a new package.
- Checks:
- Fizz’s tests were run first, to confirm the expected failures: before installing packages they failed because a module was missing, and after installing they failed because the implementation did not exist. The test files were not changed.
- The type check, lint and app tests passed, and after the second push to the same PR the whole
npm run verifypassed. The first run was blocked when downloading the database image for server tests hit a request limit (429); it passed when run again later. - GitHub CI
verifyande2eboth passed on the commit being merged.
| Item | Content |
|---|---|
| Built | Login that survives a restart, one refresh on expiry, a “try again” screen |
| Fixed after review | Retry screen hidden; late refresh reviving the key after logout |
| What I decided | On a revoked-session answer (session_revoked), end the session and go to the login screen (4A) |
| Checks | CI (verify, e2e) passed; app tests passed |
| Not done | Running on a real device or simulator |
Problems Found in Review
In the final review where PL (Claude Opus 5.5) only read the code, 2 required findings came up, and the cloud session fixed them in the same PR.
- If the startup refresh failed, the “try again” screen was hidden. The splash screen kept covering it. It now comes down when startup fails.
- A refresh that finished late after logging out could bring the key back. A session number was added, and if the number when the refresh started differs from the number when it finishes, nothing is saved. The 401 retry of a request checks the same number.
- Two low-risk findings were also applied. Logout always updates the state and navigates even if deleting from storage fails, and the button is disabled while “try again” is running.
What I Decided
The review asked what to do when a normal request gets a 401 session_revoked (the server’s answer that it ended that session), and I chose 4A, the recommended option. When this answer arrives, the session ends (the key and access token are deleted) and the app goes to the login screen, while an expired token (token_expired) is still refreshed once as before. Fizz wrote new tests for this, and before the implementation 2 of the 3 failed saying the user was still signed in (the expected failure). They passed after the implementation.
Who Did What
- I: requested the work and decided the session-ended handling as 4A.
- Cloud session (Claude Sonnet 5.5): implemented login persistence and applied the review findings and 4A.
- Fizz (GPT-6 Luna): wrote the tests, and after the review added the race test and the session-revoked test.
- Claude (PL, Sonnet 5.5): handled the instructions, integration and PR cleanup.
- Claude (PL, Opus 5.5): did the final review, reading only the code.
- Pollen (OpenCode free model glm-5.3-flash-free): did the general review.
What Was Chosen and What Was Left
- Chosen: When the session changes, the result of an old session’s refresh is thrown away, so a late request cannot overwrite the new session.
- Left:
- The call that changes screens during app startup may run before the screen group is attached. The review pointed out that the login screen might then appear instead of the suspended or withdrawn notice. It was decided to fix this separately after checking on a device, and it is not in this PR.
- Requests have no time limit, so logout may not respond for a long time if the connection hangs. This is also not in this PR.
- When a refresh takes long, a blank screen (the splash) keeps showing.
What Could Not Be Checked
- It was not run on a real device or simulator. Because the tests replace screen navigation with a fake, the order of navigation right after app startup was not confirmed.
Lessons Learned
Where asynchronous requests overlap, as in login persistence, the case where a request that finishes later overwrites the current state needs its own test. A review that read the code caught this race, and the session number and tests were added after it.