Firebase keeps syncing three-way binded object when logged out

97 views Asked by At

I sync a list of friends for $uid (defined as userId in my code) using the three-way data binding method of Firebase.

I noticed that when on the same computer (I test in the same browser) I logout and then login with another email, then Firebase keeps syncing the data from the previous userId

So if I first login and my userId = "userId_1" and then logout, login with another email and my userId = "userId_2", in my friendsList I get a three-way data binded list of friends from the refs:

fbREF + "/friends/" + "userId_1"

and

fbREF + "/friends/" + "userId_2"

How can I stop syncing the data from old userId?


Method

In my factory, I sync as follows:

    self.syncFriends = function(userId) {
        var ref = new Firebase(fbREF + "/friends/" + userId);
        return $firebaseObject(ref);
    };

where fbREF = "https://CUSTOMREF.firebaseio.com";

When the user is logged in, obviously he has an userId retrieved by the function ref.onAuth(fnCallback), which I call as follows:

self.checkSocialAuthState = function() {
      var qCheck = $q.defer();

      // --
      function authDataCallback(authData) {
        if (authData) {
          qCheck.resolve(authData);
        } else {
          qCheck.reject("SOCIALAUTH_LOGGED_OUT")
          console.log("User is logged out");
        }
      };

      // --
      var ref = new Firebase(fbREF);
      ref.onAuth(authDataCallback);

      return qCheck.promise;
    };

Then the userId is embedded in authData["auth"].uid.

1

There are 1 answers

0
Ajay Parsana On

Unless you execute unauth() method connection is active at firebase end. Hence please execute unauth() on logout. It should resolve your problem.