0

After I click logout button, the app log user out successful. But when the new user logged in it shows data of the previous user of the same device until I close the app (swipe up on iPhone) and opens again then it fetches current user data. The Firebase data are fetched of the current user but rest API data are fetched of the previous user and when I close and open the app it fetches new user data.

I have tried you clear data using shared preferences and I even installed path_provider: ^2.0.12 to clear the cache on log out pressed, but it still shows previous user data until I close the app and reopen

Future<void> _deleteCacheDir() async {
    Directory tempDir = await getTemporaryDirectory();
    
      if (tempDir.existsSync()) {
        tempDir.deleteSync(recursive: true);
      }
    }
    
    Future<void> _deleteAppDir() async {
     Directory appDocDir = await getApplicationDocumentsDirectory();

      if (appDocDir.existsSync()) {
        appDocDir.deleteSync(recursive: true);
      }
    }

and here is my code for clear data using shared preference

Future<void> clearAllData() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  await prefs.clear();
}

and Firebase logout function

 Future<void> logout() async => await _auth.signOut();

what should I do please, am stuck

I have tried to check some solution on stackoverflow here like

https://stackoverflow.com/questions/74839200/after-new-login-app-show-old-user-data-from-firebase

https://stackoverflow.com/questions/68812231/after-log-out-and-new-login-still-shows-old-user-data

Ken White
  • 123,280
  • 14
  • 225
  • 444
cmm
  • 11
  • 4
  • User data should not be stored in `stored_preferences` anyway, as it's stored in unencrypted plain text on the device. You should be using a local storage package with encryption support like `flutter_secure_storage` or `hive`. – Abion47 Feb 10 '23 at 18:40
  • @Abion47 thanks for the suggestion I will try to use local storage with encryption, so how can I currently solve the above problem – cmm Feb 10 '23 at 20:11
  • Pretty hard to say. You've posted the functions that perform the deletions but not where those functions are actually called. If your data isn't being deleted, then the first place to look is where you are calling the functions and then ask yourself if that is where they should be getting called. – Abion47 Feb 10 '23 at 23:20

0 Answers0