12

I'm facing an issue where when I sign out a user (using FirebaseAuth.signOut() method) and sign in with another user, information of the previous user are loaded instead of the new one.

I believe this is caused by this information still being accessible in firebase's cache.

Is there a way to force firebase to clear its local cache?

Cheers!

Théo Champion
  • 1,701
  • 1
  • 21
  • 46
  • I'm getting the same problem, were you able to resolve this by - FirebaseFirestore.instance.clearPersistence(); ? –  Sep 06 '21 at 17:05

3 Answers3

6

For Android, there is FirebaseFirestore.clearPersistence().

For JavaScript/web, there is Firebase.clearPersistence().

For iOS, there is Firebase.clearPersistence().

Flutter does not seem to have this API yet.

Bear in mind that the clearPersistence API is not meant for the specific case you're talking about. If you read the API docs carefully, you can see they're meant for testing.

You might want to do a little more debugging to figure out what exactly it is that's not working the way you expect. Since you're not showing any code, it's hard to tell if you might be doing something wrong.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
5

You can use the async call FirebaseFirestore.instance.clearPersistence(); for flutter projects. Check this answer.

Dpedrinha
  • 3,741
  • 3
  • 38
  • 57
  • Are you using Global variables to manage user login data? I had some user's Global variables and I had this issue too. Since I started using provider for state management this issue is gone. – Richardd Apr 10 '21 at 15:36
0

If clearPersistence() doesn't work, Programmatically restart your app

you can restart your app like this: https://stackoverflow.com/a/50116077/10041654

in addition, while restarting init your firebase: https://github.com/The-ring-io/flutter_phoenix/issues/27#issue-1490150037

Argus Waikhom
  • 186
  • 6
  • 14