How to store data in Firebase along with Authentication data

我怕爱的太早我们不能终老 提交于 2020-01-16 19:34:08

问题


I have integrated Firebase Authentication with Android App. Now I have to store other app related data like user extended profile, user preferences, settings etc.

According to Firebase documentation, Realtime database can be used to save any data.

  1. Is this the correct approach or is there any other way in firebase to store data?
  2. If this is the correct approach, what database name should I use here? I meant where to create the database in Firebase?

    FirebaseDatabase database = FirebaseDatabase.getInstance(); 
    DatabaseReference myRef = database.getReference("<<Database Name>>");
    

回答1:


Yes, this is the correct approach. If you are using firebase authentication to sign in a user using email for example, then you have to use firebase realtime database to be able to store other information related to the user example:

Users
  userid 
     name:userx
     email: userx@gmail.com
     age: 102
  userid1
      name: usery
      email:usery@gmail.com
      age: 200

To be able access the instance of the database with child node Users you can do this:

 DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("Users");

Or this:

FirebaseDatabase database = FirebaseDatabase.getInstance(); 
DatabseReference ref=database.getReference().child("Users");

No need to write the name of the database inside the getReference("<name here>");. This was needed in the old versions but it is not needed now.



来源:https://stackoverflow.com/questions/48682346/how-to-store-data-in-firebase-along-with-authentication-data

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