title: Firebase Simple Login - Can I watch event when user remove his account?
body: <p>In my app any user (signed up via Firebase Simple Login) can has 1 of 3 possible statuses at a time, that is one of <code>active</code>, <code>deleted</code> and <code>suspended</code>. I kept it like this:</p>
  
  <pre><code>"users": {
    "simplelogin:1": {
      "username": "user1",
      "email": "user1@example.com",
      "status": "active"
    },
    // ...
  }
  </code></pre>
  
  <p>Any activity that involves any user will check his/her status, if it is <code>deleted</code> or <code>suspended</code> the action cannot be done.</p>
  
  <p>Normally when user choose to remove his account from my app it would be like this:</p>
  
  <pre><code>var ref = new Firebase("https://my-app.firebaseio.com");
  
  ref.child('users/simplelogin:1/status').set('deleted', function (error) {
    if (!error) {
      ref.removeUser({
        email: "user1@example.com",
        password: "secretpassword"
      });
    }
  });
  </code></pre>
  
  <p>The problem is that user can remove his/her account without updating <code>status</code> to <code>deleted</code> first. For example this can be done by the user on his own browser console or on Node.js:</p>
  
  <pre><code>var ref = new Firebase("https://my-app.firebaseio.com");
  
  ref.removeUser({
     email: "user1@example.com",
     password: "secretpassword"
  });
  </code></pre>
  
  <p>This way the user will not has his account on Firebase but the <code>status</code>  of this user that I kept above will remain <code>active</code>, and so my app will allow any activity for that user (such as someone sending him a gift, which shouldn't be allowed if his <code>status</code> has updated to <code>deleted</code> correctly.) That could be a problem. How can I update the <code>status</code> to <code>deleted</code> when user remove his/her account?</p>
  
  <p>The solution I thought of is to regularly run cron job to check all the users in Firebase, try to sign up for users that <em>does not</em> has status <code>deleted</code> with random password and check if receive <code>EMAIL_TAKEN</code> error. If it can sign up, that means the user has already removed his/her account but the <code>status</code> in Firebase hasn't updated to <code>deleted</code>. In this case it has to update status to something (such as <code>suspicious</code> or <code>deleted</code>) and remove this newly signed up account again. I think this might be implemented like this:</p>
  
  <pre><code>// Assume this ref authenticated with admin privilege.
  ref.child('users').on('child_added', function (snap) {
    var user = snap.val();
  
    if (user.status !== 'deleted') {
      // Assume _generateRandomPassword gives generated random password.
      var password = _generateRandomPassword();
      var credentials = {
        email: user.email,
        password: password
      };
  
      ref.createUser(credentials, function (error) {
        if (!error) {
          snap.ref().child('status').set('deleted');
          ref.removeUser(credentials);
        }
      });
    }
  });
  </code></pre>
  
  <p>I think this might not be a good solution since the system has to run for every user (that does not has <code>deleted</code> status), e.g. every night. Is there a better solution to this problem?</p>