Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
658 stars 90 forks source link

userId is undefined when used in publishComposite #218

Closed mvcdev closed 7 years ago

mvcdev commented 7 years ago

We're using this package: https://github.com/englue/meteor-publish-composite. Not sure on which side is the issue.

We have the following publication: Meteor.publishComposite('candidates', function() { return { find() { return Candidates.find(); }, children: [ { find(candidate) { return Jobs.find(candidate.jobId); } } ] }; });

We have the following hook: Jobs.before.find(function (userId, selector, options, cursor) { // userId is undefined when it's called from children publication });

namirsab commented 7 years ago

@mvcdev i'm not sure if publishComposite is also hooking on the find method somehow. I need to check but i can't do it right now. Can you maybe write a small repro project?

mvcdev commented 7 years ago

Hi @namirsab! Here is the new repository. Here is the piece of code illustrating the issue: https://github.com/mvcdev/todos/blob/master/imports/api/tasks.js#L7-L36

zimme commented 7 years ago

I'm pretty sure this is related to meteor/meteor#8031 and meteor/meteor#8629 which @mitar and I are working on to get fixed.

mitar commented 7 years ago

People should just start using https://github.com/peerlibrary/meteor-user-extra. ;-)

zimme commented 7 years ago

This issue does not lie in this package. publish-composite runs the children code on the server implicitly in new fibers without binding the environment​, which makes the in current invocation being lost and the accompanying userId.

I'll put together a PR some time this week.

zimme commented 7 years ago

I'm closing this as https://github.com/englue/meteor-publish-composite/pull/105 should resolve this.