Implement clearing user data on logout
This commit is contained in:
@@ -104,9 +104,32 @@ class StorageService {
|
||||
return _secureStorage.write(key: key.name, value: value);
|
||||
}
|
||||
|
||||
/// Clears the JWT token from secure storage.
|
||||
Future<void> 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<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();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -161,7 +161,7 @@ class _HomePageState extends State<HomePage> with RouteAware {
|
||||
}
|
||||
|
||||
Future<void> _handleLogout() async {
|
||||
await _storageService.clearToken();
|
||||
await _storageService.clearAllUserData();
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user