Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot sign in user to Firebase in Android app

When I entered correct email address and password in "owners" object. run time error comes this :

E/RecaptchaCallWrapper: Initial task failed for action RecaptchaAction(action=custom_signInWithPassword)with exception - There is no user record corresponding to this identifier. The user may have been deleted.

After login, I want to go to profile page.

This is my login.java

public class owner_login extends AppCompatActivity {
    EditText textEmail, textPswd;
    Button buttonSignupOwner, buttonLogin;
    FirebaseAuth mAuth;
    private DatabaseReference mDatabase;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_owner_login);
        FirebaseAnalytics.getInstance(this).setAnalyticsCollectionEnabled(true);
        FirebaseAnalytics.getInstance(this).setUserProperty("debug", "true");
        mAuth = FirebaseAuth.getInstance();
        mDatabase = FirebaseDatabase.getInstance().getReference().child("owners");
        textEmail = findViewById(R.id.editTextEmail);
        textPswd = findViewById(R.id.editTextPassword);
        buttonLogin = findViewById(R.id.buttonLogin);
        buttonLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String email = textEmail.getText().toString().trim();
                String password = textPswd.getText().toString().trim();
                if (TextUtils.isEmpty(email)) {
                    textEmail.setError("Email is required");
                    return;
                }
                if (TextUtils.isEmpty(password)) {
                    textPswd.setError("Password is required");
                    return;
                }
                mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener < AuthResult > () {
                    @Override
                    public void onComplete(@NonNull Task\ < AuthResult\ > task) {
                        if (task.isSuccessful()) {
                            FirebaseUser user = mAuth.getCurrentUser();
                            String userId = user.getUid();
                            mDatabase.child(userId).addValueEventListener(new ValueEventListener() {
                                @Override
                                public void onDataChange(@NonNull DataSnapshot snapshot) {
                                    String username = snapshot.child("username").getValue(String.class);
                                    String email = snapshot.child("email").getValue(String.class);
                                    Intent intent = new Intent(owner_login.this, owners_Profile.class);
                                    intent.putExtra("username", username);
                                    intent.putExtra("email", email);
                                    startActivity(intent);
                                    finish();
                                }
                                @Override
                                public void onCancelled(@NonNull DatabaseError error) {
                                    Toast.makeText(owner_login.this, "Failed to retrieve user information", Toast.LENGTH_SHORT).show();
                                }
                            });
                        } else {
                            Toast.makeText(owner_login.this, "Authentication failed", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            }
        });
    }
}
like image 664
Hasini Thilakarathna Avatar asked Sep 16 '25 21:09

Hasini Thilakarathna


1 Answers

The error message is quite explicit: there is no user in the project with the email address you entered. This means that you'll have to call createUserWithEmailAndPassword to create that user first, before you can sign in with signInWithEmailAndPassword.

To prevent getting this error, you may want to call fetchSignInMethodsForEmail with just the email address - to see if Firebase has a email/password account for the email address the user enteres.

like image 174
Frank van Puffelen Avatar answered Sep 19 '25 11:09

Frank van Puffelen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!