You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何Firestore中不显示注册用户的邮箱与全名?

Firebase Firestore无法查看注册用户邮箱和全名的排查方案

我在Firebase Firestore中无法查看到注册用户的邮箱和全名,已经卡了好几个小时,求解决办法。注册代码如下:

if(valid){
    //user reg process
    mAuth.createUserWithEmailAndPassword(emailReg.getText().toString(),passwordReg.getText().toString()).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
        @Override
        public void onSuccess(AuthResult authResult) {
            userID = mAuth.getCurrentUser().getUid();
            Toast.makeText(xRegister.this, "Registration Complete", Toast.LENGTH_SHORT).show();
            DocumentReference df = mStore.collection("Users").document(userID);

            Map<String,Object> userInfo = new HashMap<>();
            userInfo.put("FullName", fullNameReg.getText().toString());
            userInfo.put("Email",emailReg.getText().toString());
            userInfo.put("Student I.D.",studentId.getText().toString());
            //access level of admin an user
            userInfo.put("isUser","1");

            df.set(userInfo).addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void unused) {
                    Log.d(TAG,"onsuccess: profile stored!" + userID);
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.d(TAG1,"failure" + e.toString());
                }
            });

            startActivity(new Intent(getApplicationContext(),xLogin.class));
            finish();
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            Toast.makeText(xRegister.this, "Error Signing Up", Toast.LENGTH_SHORT).show();
        }
    });
}

排查建议

  • 检查Firestore安全规则:默认规则可能限制了数据读取,开发阶段可临时设置开放规则(上线前务必修改为严格权限):
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}
  • 查看失败日志:打开Logcat,搜索TAG1的日志,确认df.set()是否有失败信息,比如权限不足、字段为空或网络问题。

  • 验证输入值有效性:在userInfo.put()前添加日志,确认输入控件是否获取到内容:

Log.d(TAG, "FullName: " + fullNameReg.getText().toString());
Log.d(TAG, "Email: " + emailReg.getText().toString());

如果输出为空,检查控件ID是否绑定正确,或输入是否为空。

  • 调整异步操作顺序:df.set()是异步操作,当前代码在写入未完成时就跳转页面,可能导致写入中断。将startActivity和finish移至df.set()的onSuccess回调内:
df.set(userInfo).addOnSuccessListener(new OnSuccessListener<Void>() {
    @Override
    public void onSuccess(Void unused) {
        Log.d(TAG,"onsuccess: profile stored!" + userID);
        // 确认写入完成后再跳转
        startActivity(new Intent(getApplicationContext(),xLogin.class));
        finish();
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception e) {
        Log.d(TAG1,"failure" + e.toString());
    }
});
  • 可靠获取用户ID:使用authResult.getUser().getUid()替代mAuth.getCurrentUser().getUid(),避免因当前用户状态未同步导致ID获取错误:
userID = authResult.getUser().getUid();

内容的提问来源于stack exchange,提问作者naodaddy_

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 07:55:19