Update AccountsServer.userId to also check the publication invocation

This change will make `Meteor.userId()` available in publications as
well as methods.
This commit is contained in:
Simon Fridlund
2017-05-06 22:51:52 +02:00
parent 3effe52839
commit 4372f59655

View File

@@ -77,9 +77,9 @@ export class AccountsServer extends AccountsCommon {
// user expects. The way to make this work in a publish is to do
// Meteor.find(this.userId).observe and recompute when the user
// record changes.
var currentInvocation = DDP._CurrentInvocation.get();
const currentInvocation = DDP._CurrentInvocation.get() || DDP._CurrentPublicationInvocation.get();
if (!currentInvocation)
throw new Error("Meteor.userId can only be invoked in method calls. Use this.userId in publish functions.");
throw new Error("Meteor.userId can only be invoked in method calls or publications.");
return currentInvocation.userId;
}