简体   繁体   中英

can I use sharedPreference to get current user data instead of FirebaseAuth.instance.currentUser.email Flutter

now I am learning flutter for chat app, I need to get currentUserEmail, now I have two ways to save currentUserEmail, a. save it in sharedPreference; b. always get it from FirebaseAuth

So here is my question:

  1. does FirebaseAuth.instance.currentUser.email Flutter count to one time read from firesbase(since currentUserEmail value will be used multiple times in my app, it may increase the cost)
  2. is it safe to get currentUserEmail and then save it in sharedPreference, so in the future I can easily get this currentUserEmail from sharedPreference instead of always get this from FirebaseAuth. I am afraid hacker can change this currentUserEmail value locally, so the app may treat this user as someone else.

thank you for any info in advance and keep safe!

Regarding reading data from your Firestore and whether it'll affect the cost of using Firebase, a similar question was answered there:

So a short answer is - yes, it may affect , but you can reduce the cost by implementing solutions from the linked articles.

Regarding saving the user's email in the preferences - yes, you can save it as long as the authentication in your application doesn't rely on the email address only. If you're using any Authentication service (such as Firebase Auth ), then changing email in the preferences won't cause any issues with user's authentication.

There is no need to cache the values of FirebaseAuth.instance.currentUser in sharedPreference yourself, as the Firebase SDK already caches this value for you. There is no cost for accessing FirebaseAuth.instance.currentUser or any of its properties.

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