Wednesday 2 October 2013

Meteor publish - How to publish data and check using profile information

Meteor publish - How to publish data and check using profile information

My question is really simple but unfortunately I didn't found anywhere.
I have a collection of maps for example and I'm using
Meteor.user().profile.mapsId to check if that user is allowed to see that
maps.
First approach:
server/server.js
Meteor.publish('map', function (mapOwner) {
var user = Meteor.user();
var mapId = user.profile.mapId;
return Map.find({mapOwner: mapId});
});
Didn't work because publish don't accept Meteor.user();
Second approach:
server/server.js
Meteor.publish('map', function (mapOwner) {
return Map.find({mapOwner: Meteor.call('mapsCall')});
});
collections/maps.js
Map = new Meteor.SmartCollection('map');
Meteor.methods({
mapsCall: function() {
var user = Meteor.user();
var startupId = user.profile.startupId;
return startupId;
}
});
When I call Map.find().fetch() don't have anything..
What is the right approach?

No comments:

Post a Comment