[英]Create user with firebase admin sdk that can signIn using email and password
[英]I am unable to create user with email and password with firebase
我正在尝试使用 email 和密码创建用户,如果任务成功,则将其详细信息存储在 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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.