【问题标题】:How to bind firebase database user and user data如何绑定firebase数据库用户和用户数据
【发布时间】:2020-12-17 16:39:41
【问题描述】:

我真的不知道要针对这个特定问题搜索什么,但最近我刚刚做了 使用 firebase 在我的应用上提供登录/注册功能,效果很好。

我想做的事情的背景:

这个应用程序已经有一个有效的评估功能,它会给用户一个分数,并将分数存储在他们的个人资料中。

问题是我如何确保分数(和其他用户信息)将绑定到当前登录的特定用户?

如何让特定用户进行评估时,他们的分数会落入他们自己的节点?

我想要完成的示例:

>USER1 signs up.  
  
 >USER1 will take the assessment. 
     
   >After USER1 takes an assessment 
      he will go to the profile to see his results 
      as well as his basic info like fullname,username and age. 

这是我的 firebase 数据库的示例。

谢谢!我会继续搜索我只需要一点帮助,因为我真的不知道该搜索什么关于这个特定的东西。

【问题讨论】:

标签: java android firebase firebase-realtime-database


【解决方案1】:

如果用户已登录,那么您只需执行以下操作:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String userId = user.getUid();

现在您可以访问userId。那么如果你想在数据库中添加一个新的分数,你可以这样做:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference("Score");
ref.child(userId).child("result").setValue(1);

这将为您提供以下数据库:

Score
   userId
     result : 1

【讨论】:

    猜你喜欢
    • 2018-09-06
    • 2018-07-05
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 2020-11-23
    • 2015-12-20
    • 1970-01-01
    相关资源
    最近更新 更多