mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user