How to clear previous user cache data in Flutter Firebase?

Viewed 1154

I am facing a problem of whenever a user signs out FirebaseAuth.instance.signOut() and signs In with another account the previous user's data is visible. I have seen documentation and got an idea of clearing the cache data using FirebaseFirestore.clearPersistence(). I tried this in the signOut method but though previous user's data is still visible. Can anyone please solve my issue!

main.dart

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  FirebaseFirestore.instance.settings=Settings(
    persistenceEnabled: false,
  );
  runApp(MyApp());
} 

firebaseAuth.dart

  static logOut()async{
    await FirebaseFirestore.instance.clearPersistence();
    return  FirebaseAuth.instance.signOut();
  }

THANK YOU SO MUCH!

1 Answers

You probably fixed this already but I was having the same issue and what worked for me was clearing app variables when loggin out.

I created a function to clear the variables and called it right before the signOut method

Related