From 6669e2446c8ae1cd2a85032e7c5ca2a779f830c7 Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Fri, 6 Feb 2026 17:31:04 +0100 Subject: [PATCH] Implement clearing user data on logout --- lib/core/services/storage_service.dart | 29 +++++++++++++++++++++++--- lib/features/home/home_page.dart | 2 +- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/core/services/storage_service.dart b/lib/core/services/storage_service.dart index a5b2cae..5afe121 100644 --- a/lib/core/services/storage_service.dart +++ b/lib/core/services/storage_service.dart @@ -104,9 +104,32 @@ class StorageService { return _secureStorage.write(key: key.name, value: value); } - /// Clears the JWT token from secure storage. - Future clearToken() { - return writeSecure(SecureStorageKey.jwt, null); + /// Clears all user data except URL and email. + /// + /// Called on logout to ensure a clean state for the next user, + /// while preserving server URL and email for convenience. + Future clearAllUserData() async { + // Clear JWT token + await writeSecure(SecureStorageKey.jwt, null); + + // Clear all Hive boxes + final sheetAccessTimesBox = await Hive.openBox(_sheetAccessTimesBox); + await sheetAccessTimesBox.clear(); + + final configBox = await Hive.openBox(_configBox); + await configBox.clear(); + + final changeQueueBox = await Hive.openBox(_changeQueueBox); + await changeQueueBox.clear(); + + final annotationsBox = await Hive.openBox(_annotationsBox); + await annotationsBox.clear(); + + final sheetsBox = await Hive.openBox(_sheetsBox); + await sheetsBox.clear(); + + final pendingAnnotationsBox = await Hive.openBox(_pendingAnnotationsBox); + await pendingAnnotationsBox.clear(); } // --------------------------------------------------------------------------- diff --git a/lib/features/home/home_page.dart b/lib/features/home/home_page.dart index 5757a6b..2083099 100644 --- a/lib/features/home/home_page.dart +++ b/lib/features/home/home_page.dart @@ -161,7 +161,7 @@ class _HomePageState extends State with RouteAware { } Future _handleLogout() async { - await _storageService.clearToken(); + await _storageService.clearAllUserData(); if (!mounted) return;