如何将数据与身份验证数据一起存储在Firebase中 [英] How to store data in Firebase along with Authentication data

查看:94
本文介绍了如何将数据与身份验证数据一起存储在Firebase中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将Firebase身份验证与Android App集成在一起.现在,我必须存储其他与应用程序相关的数据,例如用户扩展的个人资料,用户首选项,设置等.

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.

根据 Firebase文档,实时数据库可以用于保存任何数据.

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

  1. 这是正确的方法还是Firebase中有其他方法来存储数据?
  2. 如果这是正确的方法,那么我应该在此处使用哪个数据库名称?我的意思是在Firebase中的哪里创建数据库?

  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>>");

推荐答案

是的,这是正确的方法.例如,如果您使用Firebase身份验证通过电子邮件登录用户,则必须使用Firebase实时数据库才能存储与该用户示例相关的其他信息:

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");

或者这个:

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

无需在getReference("<name here>");中写入数据库名称.在旧版本中需要使用此功能,但现在不需要.

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.

这篇关于如何将数据与身份验证数据一起存储在Firebase中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆