Doublementi
Doublementi

Reputation: 39

Firebase - User still exist after delete

When I deleted the user from the Realtime Database by clicking the bin next to it, the user disappears, its okay, but I can still log in by his email and password, and when the login is successful, the UUID of this user reappears when I write some values to subtables in the database, but without his values defined while registering.

I thought that it should be fine after 1 hour and I could have still registered him as a new user, but I can't. I deleted him 2 days ago. What is wrong, how i can delete a user permanently - not by blocking him?

Part of my main code:


public class MainActivity extends AppCompatActivity implements View.OnClickListener {

...

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //textview,buttons,progress bars, etc...
        mAuth = FirebaseAuth.getInstance();

        forgotPassword = (TextView) findViewById(R.id.forgotPassword);
        forgotPassword.setOnClickListener(this);
    }
...
    //Onclicks, textview value correctness etc...

        progressBar.setVisibility(View.VISIBLE);
        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
        

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

                if(task.isSuccessful()){
                    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

                    if(user.isEmailVerified()){
                        // redirect to user profile
                        progressBar.setVisibility(View.GONE);


                        startActivity(new Intent(MainActivity.this, ProfileDashboard.class));
                    }else {
                        progressBar.setVisibility(View.GONE);
                        user.sendEmailVerification();
                        Toast.makeText(MainActivity.this,"Check your email to verify your account!", Toast.LENGTH_LONG).show();
                    }


                }else{
                    progressBar.setVisibility(View.GONE);
                    Toast.makeText(MainActivity.this, "Failed to login! Please check your credentials", Toast.LENGTH_LONG).show();
                }
            }
        });
    }

}

Upvotes: 0

Views: 1189

Answers (3)

Alex Mamo
Alex Mamo

Reputation: 138844

While @Dabbel solution indicates removing the user from the Console, it will indeed solve the problem, but please note that this operation might not be feasible in the case of a large number of users.

So the best option that you have is to remove the user from the Firebase Auth programmatically by calling FirebaseUser#delete() which:

Deletes the user record from your Firebase project's database.

Upvotes: 1

Chaotic Pechan
Chaotic Pechan

Reputation: 966

As the mentioned comment above, deleting from Database is not same as authentication.

So to do this you may use the firebase admin SDK. You can see an example here: https://firebase.google.com/docs/auth/android/manage-users.

So basically what you can do is to delete the user from the DB, then from the Firebase Auth to avoid having that kind of issues; example:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

user.delete()
        .addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                if (task.isSuccessful()) {
                    Log.d(TAG, "User account deleted.");
                }
            }
        });

Upvotes: 1

Dabbel
Dabbel

Reputation: 2825

The Realtime Database is not the same as Authentication.

Deleting the user in Authentication will do the trick:

enter image description here

Upvotes: 3

Related Questions