5

I signed up a user in my Flutter app using FirebaseAuth.instance.verifyPhoneNumber(). This works perfectly and the user shows up in my Firebase Console.

FirebaseAuth.instance.currentUser() now returns the user for me whenever I open the app. Should I store user info (age, weight etc.) here, or should I create a users collection in my Database and link the currentUser().uid in there?

Also, should I store it on the Database linked against the uid, or linked against the login info. For example, link a user to the phoneNumber and not the uid. Because if you ever delete the user, but they want to register again, then they will get a new uid, but their phoneNumber / email will still stay the same and can therefore still link to their old data.

Paul Kruger
  • 2,094
  • 7
  • 22
  • 49

1 Answers1

7

You can't add arbitrary data to the Firebase Authentication user profile. So you should store the additional data in a database, and indeed associate it with the UID of the user, so that you can easily look it up. This also allows you to implement searches for users more easily, as the client-side Firebase Authentication SDKs have no functionality to look up data for any user but the currently signed in one.


To the additional question: if a user deletes their account from your application, you should respect their wishes and delete the additional data that you store for them too.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thank you for this! One question though, should I store the `user` linked to the `phoneNumberr / email` or linked to the `uid`? I feel like, if the user ever deletes and re-registers, then the `phoneNumberr / email` will still hold their info. But they will get a new `uid` which then can't link to the old profile? Or should it just be updated? – Paul Kruger Jun 29 '19 at 12:36