title: SocketIO syncUpdate model for different user
body: <p>I have been writing an web app, where individual user will post their task and will be displayed on their news feed. I have used socket io with angular fullstack framework by yeoman.</p>
  
  <p>what I am trying to do is, when user adds new data to goal model, on socketSyncUpadtes, $rootScope.getUserGoals get updated and user see new entry. but I want that to happen for each user, thats why I included userid, to make sure, it only pulls user specific data.</p>
  
  <p>But in reality what is happening is, all connected user getting this socket stream and getting their model updated too, but as page refreshed it is always only what that query pulls, only user specific data.</p>
  
  <p>this is how I get user specific data</p>
  
  <pre><code>$rootScope.getUserGoals   = function (userid){
    //get current todo task views
    $http.get('/api/goals/name/'+userid).success(function(goals) {
        $rootScope.userGoalArr = goals;
        socket.syncUpdates('goal', $rootScope.userGoalArr);
      });
   };
  </code></pre>
  
  <p>then it displays in view with this</p>
  
  <pre><code> &lt;ul class = "holdTaskul" ng-repeat="view in filtered = userGoalArr | orderBy:'-created'"&gt;      
  </code></pre>
  
  <p>I looked up on google and search a lot to figure out how to separate each user socket stream and attached them to their login credential. I have come across this socket-jwt and session token. I am not expert on socket. I would much appreciate if someone could point me to right direction about this, what I am intending to do..</p>
  
  <p>my socket configuration is as follows for socket.syncUpdate function</p>
  
  <pre><code> syncUpdates: function (modelName, array, cb) {
      cb = cb || angular.noop;
  
      /**
       * Syncs item creation/updates on 'model:save'
       */
      socket.on(modelName + ':save', function (item) {
        var oldItem = _.find(array, {_id: item._id});
        var index = array.indexOf(oldItem);
        var event = 'created';
  
        // replace oldItem if it exists
        // otherwise just add item to the collection
        if (oldItem) {
          array.splice(index, 1, item);
          event = 'updated';
        } else {
          array.push(item);
        }
  
        cb(event, item, array);
      });
  
      /**
       * Syncs removed items on 'model:remove'
       */
      socket.on(modelName + ':remove', function (item) {
        var event = 'deleted';
        _.remove(array, {_id: item._id});
        cb(event, item, array);
      });
    },
  </code></pre>
  
  <p>I have also configured socket for sending auth token by this</p>
  
  <pre><code>   // socket.io now auto-configures its connection when we ommit a connection url
  var ioSocket = io('', {
    // Send auth token on connection, you will need to DI the Auth service above
    query: 'token=' + Auth.getToken(),
    path: '/socket.io-client'
  });
  </code></pre>
  
  <p>and used socketio-jwt to send the secret session to socket service by that</p>
  
  <pre><code> module.exports = function (socketio) {
    socketio.use(require('socketio-jwt').authorize({
      secret: config.secrets.session,
      handshake: true
    }));
  </code></pre>