I am trying to send a verification email after successful registration of user. Which gives me the error An internal error has occurred. [ USER_NOT_FOUND ]
. This is the code I have at present -
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());
}
}
});
}
and here is the log which is getting printed -
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.
Please have a look and let me know in case I am doing anything wrong here.
If you haven't yet connected your app to your Firebase project, do so from the Firebase console. Enable Email/Password sign-in: In the Firebase console, open the Auth section. On the Sign in method tab, enable the Email/password sign-in method and click Save.
To customize your Firebase project's email action handler, you must create and host a web page that uses the Firebase JavaScript SDK to verify the request's validity and complete the request. Then, you must customize your Firebase project's email templates to link to your custom action handler.
I also had the same issue, and the reason i found behind this is, if you are trying this code with same user which you have already created and then deleted it from firebase console, it will not work.
Try with new email address which you have not tried a single time, and it will work.
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
I am having the same problem. What I found out is that, mAuth.getCurrentUser().sendEmailVerification() is not working inside mAuth.createUserWithEmailAndPassword(email,password) method. I wrote the code outside the createUserWithEmailAndPassword(email,password) method and bang I received the verification email. Strange.
FirebaseUser user= FirebaseAuth.getInstance().getCurrentUser();
if(user!=null){
user.sendEmailVerification().addOnCompleteListener(MainActivity.this,new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
Log.i("Success","Yes");
}
else {
Log.i("Success","No"+task.getException());
}
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With