``Meteor.publish`` does NOT rerun after login


Hi guys,

hmmm… I am probably doing missing something really stupid here…

I’d to publish a collection only to logged in users.

The problem is that it DOES NOT load data AFTER a login, until I do a hot-page refresh.
So basically Meteor.publish does NOT rerun after a normal LOGIN.

This is the code.

Meteor.publish('items', function() {
  // restrict to logged in!

  console.log('run publication');
  // reactive rerun
  if (this.userId) {
    return Items.find();
  } else {
    console.log('stop publication!');

Any ideas what how to get this working?


well, you unsubscribed him from server so you would need to run subscribe again.
official example from docs

Meteor.publish("secretData", function () {
  if (this.userId === 'superuser') {
    return SecretData.find();
  } else {
    // Declare that no data is being published. If you leave this line
    // out, Meteor will never consider the subscription ready because
    // it thinks you're using the added/changed/removed interface where
    // you have to explicitly call this.ready().
    return [];


Yeah man!!!

That’s it!!!

Now I need to find a way to hook this up elegantly to the login hook… :smile: