Reputation: 1147
In meteor, is there a way to run something before every publish. Something like (pseudo) Metoer.onBeforePublish?
A use case would be to add a protection layer to all the publish functions, for example:
if (!this.userId) {
return this.ready()
}
Upvotes: 0
Views: 66
Reputation: 1147
Thanks to MasterAM comment, here is my implementation:
pub = function(name) {
var cb = Array.prototype.pop.call(arguments)
var args = Array.prototype.slice(arguments, 1, -1)
if(Meteor.isServer) {
Meteor.publish(name, function(args){
if (!this.userId) {
return this.ready()
}
})
cb(args)
}
}
and call it like so:
pub('taxes', query, options, function(){
Taxes.find(query, options)
})
Thanks!
Upvotes: 1