javascript - Meteor: this.userId and Meteor.userId() both are null within a Meteor Method -


to boil down issue basic problem , minimum of code, i've created plain new meteor app, added accounts-password package , added following code snippet. there's test user in database.

meteor.methods({     'testmethod': function() {         console.log('test2:', this.userid); // => null         console.log('test3:', meteor.userid()); // => null     } });  if (meteor.isserver) {     meteor.publish('testpublication', function() {         console.log('test1:', this.userid); // => 1c8thy3zb8vp9e5yb         meteor.call('testmethod');     }); }  if (meteor.isclient) {     meteor.loginwithpassword('test', 'test', function() {         meteor.subscribe('testpublication');     }); } 

as can see, within publication this.userid contains correct userid. within meteor method testmethod both this.userid , meteor.userid() returning null.

is meteor bug or approach wrong?

this expected behavior. because calling method server. there no user on server hence userid on method invocation obejct (this) null. try calling client when logged in.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -