0

It sounds stupid but I cant really properly logout of my app and that is because I use multiple FirebaseAnimatedList and route on my MaterialApp

routes: <String,WidgetBuilder>{
    '/StartAppPage':(BuildContext context)=>new StartAppPage(),
    '/LoginPage':(BuildContext context)=> new LoginPage(),
    '/HomePage':(BuildContext context)=> new HomePage)
  },

So the app checks for use and routes to HomePage or Login based on is there is a user or not.

My Home page has a FirebaseAnimatedList and on my Home page there is a Logout button that do this

await googleSignIn.signOut();
await FirebaseAuth.instance.signOut();
await FirebaseDatabase.instance.goOffline();
return Navigator.pushReplacementNamed(context, '/StartApp');

to HomePage and logout the user.

But when the other user login again the List shows data of the old user and the list is usable messing my Database

How can I properly implement this and the setPersistance is off or on makes no difference

Solution: Keep a single instance of your firebase user through the app. I recommend a global variable

Omatt
  • 8,564
  • 2
  • 42
  • 144
PrimeNexes
  • 565
  • 1
  • 7
  • 17

1 Answers1

0

After signing out, what you can consider doing here is check on the current screen if the user is authenticated or not. If the user is still logged-in, display the data. If not, then navigate to a Login screen.

FirebaseAuth.instance
  .idTokenChanges()
  .listen((User? user) {
    if (user == null) {
      debugPrint('User is currently signed out!');
      // TODO: navigate to Login screen?
    } else {
      debugPrint('User is signed in!');
      // TODO: display data
    }
  });
Omatt
  • 8,564
  • 2
  • 42
  • 144