0

I'm trying to publish data specific to the author of a document in my Jobs collection. My route is setup specifically to each unique author, which I then get via FlowRouter.getParam, but it still does not produce any data. I am subscribed to the 'refiJobs' publication but I'm still struggling. Thanks for reading - help is much appreciated!

My Publication

Meteor.publish('refiJobs', function () {
  if (Roles.userIsInRole(this.userId, 'admin')) {
    var author = FlowRouter.getParam('author');
    return Jobs.find({author: author});
  } else {
    this.error(new Meteor.Error(403, "Access Denied"));
  }
});

My route:

authenticatedRoutes.route( '/admin/:author', {
  action: function() {
    BlazeLayout.render( 'default',  { yield: 'user' } );
  }
});

1 Answer 1

1

The route parameters are not directly available on the server where you are creating your publication. You need to pass your route parameter through to your publication via your subscription as follows:

Client:

Meteor.subscribe('refiJobs',FlowRouter.getParam('author'));

Server:

Meteor.publish('refiJobs',(author)=>{
  check(author,String); // be sure to check the parameter(s) to your publication
  if (Roles.userIsInRole(this.userId, 'admin')) {
    return Jobs.find({author: author});
  } else {
    this.error(new Meteor.Error(403, "Access Denied"));
  }
}); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.