Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access user/userId inside a function called by a publish

Tags:

meteor

I have a Meteor.publish in my code, that calls another function, that calls another one, and so on. Then, in the most inner function, I need to know what user is the active one.

Meteor.user() can't be used. It says

Meteor.userId can only be invoked in method calls. Use this.userId in publish functions.

and this.userId is not acessible inside the inner function.

What can be done then?

like image 688
zVictor Avatar asked Oct 06 '22 23:10

zVictor


1 Answers

Can't you just assign this.userId to a variable within the publish method and then pass that variable around?

Meteor.publish("my_channel", function() {
  var userId = this.userId;
  myFunction(userId);
});
like image 68
Rahul Avatar answered Oct 10 '22 02:10

Rahul