android - Firebase - 电子邮件验证邮件不工作 - 发生内部错误。 [ USER_NOT_FOUND ]

标签 android firebase firebase-authentication

我正在尝试在用户注册成功后发送一封验证邮件。这给了我错误 An internal error has occurred。 [ USER_NOT_FOUND ]。这是我目前的代码-

public void signUpUser(View view){

    EditText mailEditText = (EditText) findViewById(R.id.editText);
    EditText pwdEditTet = (EditText) findViewById(R.id.editText2);


    String email = mailEditText.getText().toString();
    String password = pwdEditTet.getText().toString();

    Log.d("Info",email);
    Log.d("Info",password);

    mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            try {
                AuthResult result = task.getResult();

                Log.d("Sign up", "createUserWithEmail:onComplete:" + task.isSuccessful());


                // If sign in fails, display a message to the user. If sign in succeeds
                // the auth state listener will be notified and logic to handle the
                // signed in user can be handled in the listener.
                if (!task.isSuccessful()) {
                    Toast.makeText(MainActivity.this, R.string.auth_failed,
                            Toast.LENGTH_SHORT).show();
                }else{
                    Log.d("Sign up", "Sending verification email");
                    // Sending the verification email
                    //FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

                    mAuth.getCurrentUser().sendEmailVerification()
                            .addOnCompleteListener(new OnCompleteListener<Void>() {
                                @Override
                                public void onComplete(@NonNull Task<Void> task) {
                                    if (task.isSuccessful()) {
                                        Log.d("Email Sent", "Verification Email sent.");
                                    }else{
                                        Log.d("Email Sent",task.getException().getLocalizedMessage());
                                    }
                                }
                            });
                }
            } catch (Exception e){
                Toast.makeText(MainActivity.this,R.string.user_exist,Toast.LENGTH_SHORT).show();
                Log.e("Exception",e.getLocalizedMessage());
            }
        }
    });
}

这是正在打印的日志 -

10-11 10:10:50.372 31518-31518/au.com.savedme D/Sign up: Sending verification email
10-11 10:10:51.438 31518-31518/au.com.savedme D/Email Sent: An internal error has occurred. [ USER_NOT_FOUND ]
10-11 10:11:00.429 31518-31538/au.com.savedme W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.

请看一下,如果我在这里做错了什么,请告诉我。

最佳答案

我也有同样的问题,我发现这背后的原因是,如果你用你已经创建的相同用户尝试这段代码,然后从 firebase 控制台删除它,它将不起作用。

尝试使用您从未尝试过的新电子邮件地址,它会起作用。

Note that createUserWithEmailAndPassword() not only creates the user, but also, if successful, signs the user in. When the creation and sign-in occurs when there is an existing signed-in user, there appears to be a Firebase bug related to signing out and clearing the cache for the previous user.

I was able to make your code work for a previously signed-in and later deleted user by calling signOut() before createUserWithEmailAndPassword().

reference

关于android - Firebase - 电子邮件验证邮件不工作 - 发生内部错误。 [ USER_NOT_FOUND ],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39970755/

相关文章:

javascript - 如何使用云函数将数据写入云Firestore

iOS Firebase 在应用程序内本地重置密码,而不是在重定向 url 页面上

swift - 如何从 Firebase 中检索手动输入的数据?

ios - 在 firebase 中使用 Snap 值

javascript - Firebase 帐户链接错误

android - 在运行 Android 10 的小米设备上,EditText TextInput 中的电子邮件崩溃

android - Xamarin Android XamarinBuildAndroidAarRestore 任务无法从 Xamarin.Build.Download 加载

android - 在 sqlite 中正确升级表

C# 和 Android/Java - 跨语言二进制流编写器/读取器? (对于原语和 UTF-8 字符串)

ios - 火力基地和 swift