Name: meteor-publish-context
Owner: PeerLibrary
Description: Provide DDP._CurrentPublish with access to current publish context
Created: 2017-03-21 09:03:26.0
Updated: 2017-10-26 11:46:25.0
Pushed: 2018-01-15 10:09:59.0
Homepage: https://atmospherejs.com/peerlibrary/publish-context
Size: 6
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
DDP._CurrentPublish
with current publish contextAdding this package to your Meteor application creates a DDP._CurrentPublish
environment variable which you can use to access current publish context (this
inside publish function)
from anywhere in the server-side code, if that server-side code was called from a publish function.
It is similar to existing undocumented DDP._CurrentInvocation
which does the same for method calls,
giving you access to the current context of a method call (this
inside a method's body).
Not needed with Meteor >= 1.5.1. There is DDP._CurrentPublicationInvocation
now available,
and DDP._CurrentInvocation
has been renamed to DDP._CurrentMethodInvocation
. This package
provides the same functionality for previous Meteor versions.
Server side only.
or add peerlibrary:publish-context
After adding the package, you have to depend on, or import, Meteor's core ddp
package to
get access to the DDP
symbol.
Implementing a userId()
function on the server-side, which works in any code
called from methods or publish functions, can then be simply implemented as:
tion userId() {
nst currentInvocation = DDP._CurrentInvocation.get();
(currentInvocation) return currentInvocation.userId;
nst currentContext = DDP._CurrentPublish.get();
(currentContext) return currentContext.userId;
row new Error("userId() not invoked from a method or publish function.");
This is more or less what peerlibrary:user-extra
package does to provide Meteor.userId()
.