How to clear previous user cache data in Flutter Firebase?

688

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

Share:
688
REVANTH N D
Author by

REVANTH N D

I am a student at SRET,TamilNadu,India

Updated on December 26, 2022

Comments

  • REVANTH N D
    REVANTH N D over 1 year

    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!

  • ozkanpakdil
    ozkanpakdil about 3 years
    can you give code example for how to clear the app variables before signout?
  • Jairo R. Flores
    Jairo R. Flores about 3 years
    This works, but it seems weird that firebase been based on streams and a very accurate cache management by user, do this. Definitely the OP needs to give us more info on what was doing.
  • Dishank Jindal
    Dishank Jindal over 2 years
    Can you give more, as what you exactly did! because clearing variables seems easy but i am facing issues.