From 33dbd1508f5f06073dde9db3da7dd5178dd857e1 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Wed, 3 Jun 2026 15:48:02 +0200 Subject: [PATCH] Correctly delete the user's local db on logout --- lib/providers/auth_notifier.dart | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/providers/auth_notifier.dart b/lib/providers/auth_notifier.dart index 7f94ca389..c53f1f9bd 100644 --- a/lib/providers/auth_notifier.dart +++ b/lib/providers/auth_notifier.dart @@ -337,15 +337,20 @@ class AuthNotifier extends _$AuthNotifier { newState = newState.copyWith(serverConfigWarning: true); } + // Wipe the previous user's local DB BEFORE publishing the logged-in state, + // so no listener can react to the new identity while the old user's data + // and queued CRUD ops are still on disk (and uploadable under the new + // credentials). Mirrors the wipe-before-publish order of _resetSession. + if (newState.status == AuthStatus.loggedIn && userChanged) { + _logger.info( + 'different user logging in (was $prevUserId, now $newUserId), wiping local DB', + ); + await _wipeOnUserSwitch(); + } + state = AsyncData(newState); if (newState.status == AuthStatus.loggedIn) { - if (userChanged) { - _logger.info( - 'different user logging in (was $prevUserId, now $newUserId), wiping local DB', - ); - await _wipeOnUserSwitch(); - } await _reconnectPowerSyncIfBuilt(serverUrl); _invalidatePostLoginProviders(); }