The Meteor documentation clearly states that using Meteor.userId()
is not permitted within publish functions and that this.userId
should be used in it's place.
I vaguely remember seeing a warning or error in the past when doing this accidentally.
I regularly use shared code that is both used to validate rights in subscriptions as well as to determine in helpers if I should actually display a certain element to a certain user type.
This makes this approach highly annoying. By accident I used Meteor.userId() today in the following publication, without any issues.
Has this limitation been removed? And if so, is there any documentation that goes along with it as the documentation has not been updated.
I'm using Meteor 1.5.2.2.
The example publication is this ...
Meteor.publish("users.currentUser", function(){
const currentId = Meteor.userId();
return Meteor.users.find({_id: currentId}, {
fields: { services: 1, username: 1, emails: 1, roles: 1, details: 1}
});
})
Since 1.5.1 you can use Meteor.userId()
and Meteor.user()
in publications. Seems like documentation has not been updated yet.