From 4372f59655a12ead40fa4cf8affcea771977d840 Mon Sep 17 00:00:00 2001 From: Simon Fridlund Date: Sat, 6 May 2017 22:51:52 +0200 Subject: [PATCH] Update AccountsServer.userId to also check the publication invocation This change will make `Meteor.userId()` available in publications as well as methods. --- packages/accounts-base/accounts_server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/accounts-base/accounts_server.js b/packages/accounts-base/accounts_server.js index eca4c3e5a8..1dfb05d6a7 100644 --- a/packages/accounts-base/accounts_server.js +++ b/packages/accounts-base/accounts_server.js @@ -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; }