0

那么,我可以访问当前FirebaseUser对象为FirebaseAuth.getInstance().getCurrentUser(),然后我可以拨打getPhotoUrl()getDisplayName()方法。 问题在于用户UUID,如何访问另一个用户的对象并调用这些方法?如何访问其他FirebaseUser的属性?

PS:在Android

+0

这将被称为安全漏洞......怀疑你会做到这一点。 – theblindprophet

+0

@theblindprophet所以我应该让自己的JSON树来保持这些信息并在用户之间正确共享吧?这不是冗余,以保持相同的信息两次? – guness

+1

如果您希望其他用户有权访问信息,那么请使用该信息创建您自己的子树。 – theblindprophet

回答

0

常见的方式做,这是存储有关的火力地堡数据库中的用户可共享信息。

firebase.com上的文档有一个很好的例子。请参阅https://www.firebase.com/docs/android/guide/user-auth.html#section-storing尽管您需要稍微修改代码,但该方法与新的Firebase更改仍然相同。

我会添加一条说明,我们需要将这个示例添加到新的Firebase文档中。

0

FirebaseUser具有一组固定的基本属性 - 唯一ID,主电子邮件地址,名称和照片URL,存储在单独项目的用户数据库中;这些属性可以由用户更新。您无法直接将其他属性添加到FirebaseUser对象;相反,您可以将其他属性存储在您的Firebase实时数据库中。

FirebaseAuth mAuth = FirebaseAuth.getInstance(); 

mAuth.createUserWithEmailAndPassword("[email protected]", "my pass") 
    .continueWithTask(new Continuation<AuthResult, Task<Void>> { 
     @Override 
     public Task<Void> then(Task<AuthResult> task) { 
      if (task.isSuccessful()) { 
       FirebaseUser user = task.getResult().getUser(); 
       DatabaseReference firebaseRef = FirebaseDatabase.getInstance().getReference(); 
       return firebaseRef.child("users").child(user.getUid()).child("phone").setValue("650-253-0000"); 
      } else { 
       // User creation didn't succeed. Look at the task exception 
       // to figure out what went wrong 
       Log.w(TAG, "signInWithEmail", task.getException()); 
      } 
     } 
    }); 
相关问题