gpt4 book ai didi

java - Firebase createUserWithEmailAndPassword task.isSuccessful()

转载 作者:行者123 更新时间:2023-11-29 23:15:20 26 4
gpt4 key购买 nike

我正在创建一个 Android 应用程序并正在实现登录/注册功能。

我正处于注册 Activity 在我的 Firebase 应用程序中成功创建用户条目的阶段,但是,我似乎无法跟踪任务是否成功。

Users being created

private void startRegister() {
String email = mEmailField.getText().toString();
String password = mPasswordField.getText().toString();
String confirmPassword = mConfirmPassword.getText().toString();

// Check that fields are not empty
if (TextUtils.isEmpty(email) || TextUtils.isEmpty(password) || TextUtils.isEmpty(confirmPassword)) {

Toast.makeText(Register.this, "Email, password or confirm password field cannot be empty.", Toast.LENGTH_LONG).show();
} else if (!password.equals(confirmPassword)) {

Toast.makeText(Register.this, "Password and confirm password should match", Toast.LENGTH_LONG).show();
} else {

mAuth.createUserWithEmailAndPassword(email, password).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {

Toast.makeText(Register.this, "Success", Toast.LENGTH_LONG).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {

Toast.makeText(Register.this, "Failure", Toast.LENGTH_LONG).show();
}
});
}
}

if !task.isSuccessful() 或 else block 都会到达,但用户是在 Firebase 中创建的。为什么我无法跟踪成功/失败的任何想法?

比较:

这在我的登录类中有效。

        mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {

if (!task.isSuccessful()) {
Toast.makeText(Login.this, "Credentials error, user may not exist.", Toast.LENGTH_LONG).show();
}
}
});

最佳答案

很难说当前的实现方式如何。尝试直接添加一个 onSuccess

mAuth.createUserWithEmailAndPassword(email, pass).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
//done
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
//display toast if registering failed
ToastRect.failed(RegisterActivity.this, getString(R.string.app_activities_error_text)
}
});

关于java - Firebase createUserWithEmailAndPassword task.isSuccessful(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55460453/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com