Dariusz Sikorski
Dariusz Sikorski

Reputation: 4407

Meteor Publish all collections only for specified user (admin)

How to publish all meteor collections only to user with {role: "admin"}? The meteor autopublish package gives db access to all clients. Is there a way to use autopublish package with some access restrictions or a function simmilar with access parameters?

(as a bonus it would be nice to have insecure package with the same restrictions, but it's not neccessary).

Upvotes: 0

Views: 43

Answers (1)

webdeb
webdeb

Reputation: 13211

Meteor.publish(null, function() {
  var user = Meteor.users.findOne(this.userId);
  // pseudo code
  if (user && user.role == "admin") {
    return [
      Col1.find(),
      Col2.find(),
      Col3.find(),
      ...
    ]
  } else {
    this.ready();
  }
});

This is an anonymous publication, (null) you don't need to subscribe to it.. it will be automatically published to the client..

Upvotes: 1

Related Questions