目前使用的是Firebase v3。我试图在用户登录后保存Firebase用户的显示名称。
到目前为止,我有以下snipet代码:
FirebaseUser fbUser = mFirebaseAuth.getCurrentUser();
if (fbUser != null) {
// User is logged in
Log.i("Task User", fbUser.getUid());
DatabaseReference userRef = FirebaseDatabase.getInstance().getReference("users").child(fbUser.getUid());
userRef.child("display_name").setValue(fbUser.getDisplayName())
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Log.i("Task Complete", task.toString());
Intent intent = new Intent(getBaseContext(), MainActivity.class);
startActivity(intent);
finish();
}
}).addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e("Task Fail", e.toString());
}
}).addOnSuccessListener(this, new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.i("Task Success", "Success");
}
});
}
设置我的Firebase规则,以便只有经过身份验证的用户才能读取或写入:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
我可以验证:
Task User
,Task Success
和Task Complete
已记录在输出但是,每当我查看实时数据库页面时,我仍然会看到myapp: null
。我有什么明显的遗失吗?