feat: Conditionally reset authentication state on force logout and streamline logout by immediately resetting state and clearing tokens.
This commit is contained in:
@@ -75,7 +75,10 @@ class AuthNotifier extends StateNotifier<AuthState> {
|
||||
// when token refresh fails
|
||||
ApiClient.onForceLogout = () {
|
||||
SocketService().disconnect();
|
||||
state = const AuthState();
|
||||
// Only reset if still authenticated — avoid showing errors on login screen
|
||||
if (state.status == AuthStatus.authenticated) {
|
||||
state = const AuthState();
|
||||
}
|
||||
};
|
||||
checkAuthStatus();
|
||||
}
|
||||
@@ -107,16 +110,16 @@ class AuthNotifier extends StateNotifier<AuthState> {
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
// Reset state first so UI navigates to login immediately
|
||||
state = const AuthState();
|
||||
// Disconnect socket immediately
|
||||
SocketService().disconnect();
|
||||
// Attempt FCM unregister and API logout (best-effort, don't block)
|
||||
// Clear tokens BEFORE any API calls to prevent 401 errors during logout
|
||||
await SecureStorage.clearTokens();
|
||||
// Best-effort cleanup — tokens already cleared, ignore any errors
|
||||
try {
|
||||
await PushNotificationService().unregister();
|
||||
} catch (_) {}
|
||||
try {
|
||||
await _repository.logout();
|
||||
} catch (_) {}
|
||||
state = const AuthState();
|
||||
}
|
||||
|
||||
Future<void> login({
|
||||
|
||||
Reference in New Issue
Block a user