Jbarget
Jbarget

Reputation: 569

Firebase: removeUser() but need to remove data stored under that uid

I'm using Firebase and need to add a removeUser() function to remove a user account however there is also data stored under that uid in the database. Is it possible for the removeUser() function to also remove that data or is the only way to run another Firebase function (remove()) as a callback?

Thanks, J

Upvotes: 2

Views: 1803

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598807

Firebase doesn't store any data about your users in your database. So if there is data about the user in your Firebase database, it is because your application stored it there. Likely you store it there when you called createUser(), as recommended in the Firebase programming guide for storing user data.

For this reason it makes sense that it's also the responsibility of your application to remove the data about a user when it calls removeUser(). This can be as simple as:

function myRemoveUser(uid, email, password) {
  ref.removeUser({ email: email, password: password }, function(error) {
    if (!error) {
      ref.child('users').child(uid).remove();
    }
  });

}

Look at the docs for removeUser() to see how it handles errors/

Upvotes: 3

Related Questions