1
votes

This app was working fine till I tried to "secure it":

  • remove insecure
  • remvoe autopublish
  • add accounts-ui accounts-password
  • made some changes to the code as below

    //both.js
    
    FooterButtons = new Mongo.Collection('footerButtons');
    Tasks1 = new Mongo.Collection('tasks1');
    Tasks = new Mongo.Collection('tasks');
    Tasks1.allow({
      insert: function (userId, doc) {
        return userId;
      }
    });
    
    
     // deny anyone that tries to update the document userId
    Posts.deny({
        update: function (userId, docs, fields, modifier) {
       // can't change owners
       return _.contains(fields, 'userId');
       }
    });
    
    //server.js 
    Meteor.publish('tasks', function(){
      return Tasks.find({userId: this.userId});
     });
    
     Meteor.publish('tasks1', function(){
       return Tasks1.find({userId: this.userId});
     });
    
    Meteor.publish('footerButtons', function(){
       return FooterButtons.find({userId: this.userId});
     });
    

Now the app is crashing with browser saying

/Users/myName/.meteor/packages/meteor-tool/.1.1.10.1b51q9m++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245 throw(ex); ^ ReferenceError: Posts is not defined at both/both.js:15:1 at both/both.js:20:4 at /Users/myName/Documents/meteor/microscope/.meteor/local/build/programs/server/boot.js:242:10 at Array.forEach (native) at Function..each..forEach (/Users/empl1/.meteor/packages/meteor-tool/.1.1.10.1b51q9m++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11) at /Users/myName/Documents/meteor/microscope/.meteor/local/build/programs/server/boot.js:137:5 Exited with code: 8 Your application is crashing. Waiting for file change.

Why is it crashing and how should it be fixed? Thanks

3

3 Answers

1
votes

You could start here:

ReferenceError: Posts is not defined at both/both.js:15:1 at both/both.js

Your are missing a collection assignment for the Posts collection.

1
votes

Based on your error message, it's because you're not defining the Posts collection. Add this line of code:

Posts = new Mongo.Collection('posts');

That will remove the error, but I think you probably copied/pasted this code from an example and want to enact a deny rule on a different collection?

0
votes

I think you already have the post collection definition somewhere in the project, because it worked before you removed the autopublish package. You should find it and put all the collection definition file into lib folder instead of any randomly named folder for the shake of order loading. Read more about the meteor app structure in here