简体   繁体   中英

Does firebase store current user data automatically on phone in flutter?

I just saw a tutorial, where the author although was using shared-ref to store the user name, email etc locally, but he didn't use anything to store currentUser on a flutter app, which was connected to firebase. and hence in splash screen, he used if currentUser,= null, then goto Home Screen. and it worked fine on restarting the app, hence to log out. again he used firebaseAuth.signOut(), so? does firebase stores currentUser automatically on the local storage of the app?

I don't think it's stored locally in terms of shared preferences/ user defaults. I had an issue where without logging out, but uninstalling and reinstalling the app resulted in the app already knowing who I was. Turns out, it was stored in keychain (on iOS, I don't know the android counterpart). See this answer for more detail on my particular understanding of how firebase saves the user:

https://stackoverflow.com/a/69621552/12132021

Firebase Authentication SDKs store the credentials of the user in local storage, and then restore the user from there when the app restarts/page reloads.

Note that this doesn't always means that currentUser != null will work on app startup/page load, as restoring the credentials requires an asynchronous call to the server and currentUser will be null until that call completes. For the best results listen/respond to authStateChanges as shown in the documentation on authentication state .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM