fix: 401 logout loop — sync state update, prevent re-navigation #53

Merged
rafaga21 merged 1 commits from feat/push-monitoring-agent-v2 into master 2026-06-11 21:13:28 -04:00
Owner

Root cause: LoginViewModel.logout() was async (viewModelScope.launch),
so _uiState.isConnected remained true after navigating to login.
LoginScreen's LaunchedEffect immediately navigated back to dashboard,
where APIs failed with 401 again → infinite loop.

Fixes:

  • SessionManager: add _invalidating flag to prevent concurrent 401 handling
  • AuthInterceptor: check isSessionValid before invalidating
  • LoginViewModel: update _uiState synchronously in logout(), clear token
    before launching coroutine for prefs.clear()
  • LoginViewModel: call SessionManager.restoreSession() after successful login
  • MainActivity: remove restoreSession() from logout handler (was incorrectly
    re-validating session right after invalidation)

Bump to v1.7.1 (versionCode 10)

Root cause: LoginViewModel.logout() was async (viewModelScope.launch), so _uiState.isConnected remained true after navigating to login. LoginScreen's LaunchedEffect immediately navigated back to dashboard, where APIs failed with 401 again → infinite loop. Fixes: - SessionManager: add _invalidating flag to prevent concurrent 401 handling - AuthInterceptor: check isSessionValid before invalidating - LoginViewModel: update _uiState synchronously in logout(), clear token before launching coroutine for prefs.clear() - LoginViewModel: call SessionManager.restoreSession() after successful login - MainActivity: remove restoreSession() from logout handler (was incorrectly re-validating session right after invalidation) Bump to v1.7.1 (versionCode 10)
rafaga21 added 1 commit 2026-06-11 21:13:10 -04:00
Root cause: LoginViewModel.logout() was async (viewModelScope.launch),
so _uiState.isConnected remained true after navigating to login.
LoginScreen's LaunchedEffect immediately navigated back to dashboard,
where APIs failed with 401 again → infinite loop.

Fixes:
- SessionManager: add _invalidating flag to prevent concurrent 401 handling
- AuthInterceptor: check isSessionValid before invalidating
- LoginViewModel: update _uiState synchronously in logout(), clear token
  before launching coroutine for prefs.clear()
- LoginViewModel: call SessionManager.restoreSession() after successful login
- MainActivity: remove restoreSession() from logout handler (was incorrectly
  re-validating session right after invalidation)

Bump to v1.7.1 (versionCode 10)
rafaga21 merged commit 3f95b061d3 into master 2026-06-11 21:13:28 -04:00
rafaga21 deleted branch feat/push-monitoring-agent-v2 2026-06-11 21:13:29 -04:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: devlab/server-manager#53