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