feat(formulus): Add auto-login on 401 errors during sync operations #237
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.
Description
Implements automatic re-authentication when 401 Unauthorized errors occur during sync operations (both data sync and app bundle updates), improving UX by preventing manual re-login.
Problem:
When users return to Formulus and attempt to sync after their auth token has expired, they encounter a 401 error and must manually navigate to Settings to re-login before syncing again.
Solution:
Type of Change
Component(s) Affected
Related Issue(s)
** Closes #143
Changes Made
Core Implementation
src/api/synkronus/Auth.tsautoLogin()function to re-authenticate using stored credentialsisUnauthorizedError()function to detect various 401 error formatssrc/api/synkronus/index.tsclearTokenCache()to also clear API instance and configsrc/services/SyncService.tswithAutoLoginRetry()wrapper method for automatic retry logicsyncObservations(),updateAppBundle(),checkForUpdates()src/screens/SettingsScreen.tsxgetApi())src/screens/SyncScreen.tsxfinishSync()is always called infinallyblockTest Coverage
src/api/synkronus/__tests__/Auth.test.ts(15 tests)isUnauthorizedError()andautoLogin()src/services/__tests__/SyncService.autoLogin.test.ts(8 tests)Bug Fixes Included
finallyblockTesting
Test Results
npm test -- Auth.test.ts SyncService.autoLogin.test.tsBreaking Changes
If breaking changes, please describe migration steps:
N/A - This is a backward-compatible enhancement.
Edge Cases Handled
Documentation Updates
Checklist