我无法使用firebase创建具有电子邮件和密码的用户



我正试图用电子邮件和密码创建用户,如果任务成功,则将他们的详细信息存储在firebase数据库中以供参考,但我不知道会发生什么。progressDialog在不创建用户的情况下继续加载。这是代码。如果有人能帮我接通,我将不胜感激

private void registerSeller() {
String sellerName = name.getText().toString();
String phoneNumber = phone.getText().toString();
String sellerEmail = email.getText().toString();
String sellerPassword = password.getText().toString();
String sellerAddress = address.getText().toString();
if (sellerName.isEmpty()) {
name.setError("Please Enter Your Name");
`enter code here`
cancel = true;
name.requestFocus();
} else if (phoneNumber.isEmpty()) {
phone.setError("Please Enter Your Phone Number");
cancel = true;
phone.requestFocus();
} else if (sellerEmail.isEmpty()) {
email.setError("Please Enter Your Email Address");
cancel = true;
email.requestFocus();
} else if (sellerPassword.isEmpty()) {
password.setError("Please Enter Your Password");
cancel = true;
password.requestFocus();
} else if (sellerAddress.isEmpty()) {
address.setError("Please Enter Your Shop Address");
cancel = true;
address.requestFocus();
} else {
loadingDialog.setTitle("Registration Processing...");
loadingDialog.setMessage("Please wait while we are checking your credentials");
loadingDialog.setCanceledOnTouchOutside(false);
loadingDialog.show();
mAuth.createUserWithEmailAndPassword(sellerEmail, sellerPassword)
.addOnCompleteListener(new OnCompleteListener < AuthResult > () {
@Override
public void onComplete(@NonNull Task < AuthResult > task) {
if (task.isSuccessful()) {
final DatabaseReference sellerRef = FirebaseDatabase.getInstance().getReference();
FirebaseUser user = mAuth.getCurrentUser();
String sid = mAuth.getCurrentUser().getUid();
HashMap < String, Object > sellerMap = new HashMap < > ();
sellerMap.put("sid", sid);
sellerMap.put("name", sellerName);
sellerMap.put("phone", phoneNumber);
sellerMap.put("email", sellerEmail);
sellerMap.put("password", sellerPassword);
sellerMap.put("address", sellerAddress);
sellerRef.child("sellers").child(sid)
.updateChildren(sellerMap)
.addOnCompleteListener(new OnCompleteListener < Void > () {
@Override
public void onComplete(@NonNull Task < Void > task) {
if (task.isSuccessful()) {
loadingDialog.dismiss();
Toast.makeText(SellerRegistrationActivity.this, "Seller Registered Successfully", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(SellerRegistrationActivity.this, SellerLoginActivity.class);
startActivity(intent);
} else {
loadingDialog.dismiss();
Toast.makeText(SellerRegistrationActivity.this, "Error Occurred", Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
}

故障排除的第一步是停止忽略潜在错误。如果Task失败,它会有一个异常来解释导致它失败的原因。您应该记录或引发该异常,以找到根本原因:

mAuth.createUserWithEmailAndPassword(sellerEmail, sellerPassword)
.addOnCompleteListener(new OnCompleteListener < AuthResult > () {
@Override
public void onComplete(@NonNull Task < AuthResult > task) {
if (task.isSuccessful()) {
...
}
else {
throw task.getException();
}
}

相关内容

最新更新