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
|
// when token refresh fails
|
||||||
ApiClient.onForceLogout = () {
|
ApiClient.onForceLogout = () {
|
||||||
SocketService().disconnect();
|
SocketService().disconnect();
|
||||||
|
// Only reset if still authenticated — avoid showing errors on login screen
|
||||||
|
if (state.status == AuthStatus.authenticated) {
|
||||||
state = const AuthState();
|
state = const AuthState();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
checkAuthStatus();
|
checkAuthStatus();
|
||||||
}
|
}
|
||||||
@@ -107,16 +110,16 @@ class AuthNotifier extends StateNotifier<AuthState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> logout() async {
|
Future<void> logout() async {
|
||||||
|
// Reset state first so UI navigates to login immediately
|
||||||
|
state = const AuthState();
|
||||||
// Disconnect socket immediately
|
// Disconnect socket immediately
|
||||||
SocketService().disconnect();
|
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 {
|
try {
|
||||||
await PushNotificationService().unregister();
|
await PushNotificationService().unregister();
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
try {
|
|
||||||
await _repository.logout();
|
|
||||||
} catch (_) {}
|
|
||||||
state = const AuthState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> login({
|
Future<void> login({
|
||||||
|
|||||||
Reference in New Issue
Block a user