How to properly implement Logout with firebase on flutter

这一生的挚爱 提交于 2019-12-25 00:39:22

问题


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

来源:https://stackoverflow.com/questions/48964709/how-to-properly-implement-logout-with-firebase-on-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!