Fix: Critical login state and authentication issues #60
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.
Fix: Critical Login State Loss & Authentication Issues
📋 Overview
This PR resolves critical issues in the login process, specifically regarding OAuth authentication (OIDC). The primary issue was that the
LoginActivitystate (and thus crucial authentication parameters) was lost when the user switched to the browser view (Custom Tabs) and returned. This resulted in login failures or app crashes/restarts, particularly on devices with aggressive memory management.🐛 The Problem
When the app opens the browser for OAuth login,
LoginActivityis pushed to the background. Android may terminate the app process at this point to reclaim memory.When the user returns after logging in:
LoginActivityis recreated (onCreate).codeVerifier,codeChallenge,serverBaseUrl) are gone.🛠 The Solution
The solution consists of three main components:
codeVerifier,codeChallenge,oidcState) are now explicitly saved toSharedPreferencesbefore the browser is opened. This is more robust thanonSaveInstanceStateas it survives complete process restarts.onCreateandonSaveInstanceState, the UI state (URL input, Auth method) is now correctly saved and restored.LoginActivityfrom being placed on the stack when the browser returns. Instead, the existing instance is reused.🔍 Detailed Code Analysis
1.
AuthenticationViewModel.kt- Mutability for RestoreWe need to make the OAuth parameters mutable so we can overwrite them when restoring the old state from storage.
2.
LoginActivity.kt- Intent & Task ManagementWhen the browser returns with the Auth Code, we don't want Android to layer a new
LoginActivityover the old one. We want to reactivate the old one.3.
LoginActivity.kt- Saving & Loading Auth StateHere lies the magic of persistence. We don't just rely on RAM.
Saving before Browser Launch:
Restoring on Start (
onCreate):Cleanup on Success:
4.
LoginActivity.kt- UI State RestorationWe ensure that the UI (input fields, button visibility) is correctly restored so the user isn't faced with an empty screen.
✅ Verification / Testing