Avoid repeating authentication in subscriptions


#1

publications in my application have the same structure

Meteor.publishRelations('users', function (options) {
  check(options, {
  	skip: Match.Integer
  });
  // Authentication
  // find the user, then check permissions and groups

  // maybe some other things that should only run once

  // the important part
  // listen = DDPServer._InvalidationCrossbar
  this.listen(options, function () {
    // cursor = send a cursor to client
    this.cursor(Meteor.users.find({}, {skip: options.skip}));
  });

  return this.ready();
});

what I want is to allow the user to call listen when skip change and run only the cursor, not the entire publication.
so, instead of stopping the subscription and re-subscribe change the current subscription

the above code works, but I have a problem, previous documents are not cleared on client until stop the subscription
if my cursor returned before 10 documents, then would 20…30 etc. because client documents are still there (but are not reactive). My question is then how do I get rid of them? or is there a better way?


#2

I will create a package with easy API if I can solve that issue
the faster I can fix it better, or somewhere where I can ask?