I am trying to add an extra information that is not in profile for the currentUser object in Meteor. I am thinking it is possible and the technique should be somewhere in meteor/alanning:roles.
e.g. if I have a organizations object in users e.g.
As @krizzli already said, you can publish additional fields (according to Meteor docs, only the profile dictionary is published by default).
If you don’t want to publish the fields, because you don’t always need them and want to avoid unnecessary network traffic, you can also use methods to set and get data. I’m using a mixture of both approaches in my app.
Problem with that approach is it requires me to subscribe to the extra user data explicitly. From alanning:roles, I don’t think I had to explicitly subscribe and it was already in my object.
The reason why I am trying to do it with the alanning:roles approach is that Meteor.users.findFromPublication would result in having only one user (the current one) show up.
I may have fixed the issues with FindFromPublication with my patch, still waiting for approval on the PR to confirm. Anyway, I think I would also need to have a resolve block to wait for the subscription containing the roles and other extra data on my user to resolve before going on. Not a big deal.
I already have, an I get a timing issue when the publish does not get there in time. Hence I am making it into a subscription that I can wait to ensure it is ready before going forward.
Note: Since we need to access context on this we need to use the function() {} form for publications rather than the ES2015 () => {}. You can disable the arrow function linting rule for publication files with eslint-disable prefer-arrow-callback. A future version of the publication API will work more nicely with ES2015.
The => syntax won’t work here since it uses the surrrounding context for this. Beware: The arrow syntax is not just a short-cut for a regular closure.