I need to be able to set the meteor user id for a string of actions initiated by a rest api endpoint call. The reason is because I am using collection-hooks, which needs to be able to read Meteor.userId(). Unfortunately, Meteor seems to be adamantly opposed to allowing me to set that value for the duration of the function. A simple call like this gives me an error: Can’t call setUserId on a server initiated method call. Why can’t this be done? I need to be able to tell Meteor to pretend like a user is logged in for this method call. I have a lot of authentication code built into meteor collection-hooks that I need to be able to use to make sure that API authentication is managed correctly. This is a major and frustrating shortcoming.
Meteor.methods({
test:function(){
this.setUserId('ebAnEgsK22w5NAghP')
//DO Some selects, inserts, updates
}
})