这是我尝试使用唯一用户 ID 更新数据的部分。但它总是显示注册失败,即使身份验证部分正在工作。mAuth.createUserWithEmailAndPassword(email,password) .addOnCompleteListener(new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { user user=new user( nameOfUser, email, phNo ); //Toast.makeText(Register_User.this, "Working", Toast.LENGTH_SHORT).show(); mData.getReference("Users") .child(Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid()) .push().setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { progressBar.setVisibility(View.GONE); Toast.makeText(Register_User.this, "Upto here", Toast.LENGTH_LONG).show(); if (task.isSuccessful()) { Toast.makeText(Register_User.this, "Successfully Registered", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(Register_User.this, "Failed to Registered", Toast.LENGTH_SHORT).show(); } } }); } else if (task.getException() instanceof FirebaseAuthUserCollisionException) { progressBar.setVisibility(View.GONE); Toast.makeText(getApplicationContext(), "You are already registered", Toast.LENGTH_SHORT).show(); } } });
1 回答
回首忆惘然
TA贡献1847条经验 获得超11个赞
如果任务失败,它会出现一个向您显示问题的异常。您目前没有以任何方式使用它,但它可能会为您指明解决方案:
if (task.isSuccessful()) {
Toast.makeText(Register_User.this, "Successfully Registered", Toast.LENGTH_SHORT).show();
} else {
Log.w(TAG, "Registering user failed", task.getException());
Toast.makeText(Register_User.this, "Failed to Registered", Toast.LENGTH_SHORT).show();
}
另请参阅Firebase 文档中的创建基于密码的帐户。
添加回答
举报
0/150
提交
取消