Implement clearing user data on logout

This commit is contained in:
2026-02-06 17:31:04 +01:00
parent b62ed98375
commit 6669e2446c
2 changed files with 27 additions and 4 deletions

View File

@@ -104,9 +104,32 @@ class StorageService {
return _secureStorage.write(key: key.name, value: value); return _secureStorage.write(key: key.name, value: value);
} }
/// Clears the JWT token from secure storage. /// Clears all user data except URL and email.
Future<void> clearToken() { ///
return writeSecure(SecureStorageKey.jwt, null); /// Called on logout to ensure a clean state for the next user,
/// while preserving server URL and email for convenience.
Future<void> 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();
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@@ -161,7 +161,7 @@ class _HomePageState extends State<HomePage> with RouteAware {
} }
Future<void> _handleLogout() async { Future<void> _handleLogout() async {
await _storageService.clearToken(); await _storageService.clearAllUserData();
if (!mounted) return; if (!mounted) return;