0

Building a collaborative app in Meteor. I am having issues with adding a user to a session. When i call my method "addUserToSession" and pass the relevant IDs, i get this error.

 Exception while simulating the effect of invoking 'addUserToSession' TypeError: Cannot read property 'editors' of undefined(…) TypeError: Cannot read property 'editors' of undefined

I want this to happen ;

  • User A starts a session.
  • Sends the link to user B
  • User B goes to the URL
  • User B has their ID added to the session record in mongo
  • Client gets the JSON in the record and updates DOM stuff.

I think it might be something to do with how i'm subscribing to the DB. Any help would be great!

Router.js

//if hit a URL with an ID
//set id session var and render sessionGrid
FlowRouter.route('/tides/:_id', {
   name: 'oceanSession',
subscriptions: function(params) {
   console.log("subscribe to sessions");
Meteor.subscribe('sessions');
Meteor.subscribe('myCollabs');
},

action: function(params) {
    Session.set('id', params._id);
     Meteor.call("addUserToSession", Meteor.userId(),Session.get('id'));
    //console.log('session id set ' + Session.get('id'));
    BlazeLayout.render('main', {
        stuff: "sessionGrid"
    })


 }
});

shared/main.js

addUserToSession:function(userId, sessionId){
    console.log(userId + " to be added to  " + sessionId);
    var editorArray = Sessions.findOne(sessionId)["editors"];
    console.log(editorArray);
    //Sessions.update({_id: sessionId}, {$push:{editors:userId}});
  }

this doesn't behave and console gets

  Exception while simulating the effect of invoking 'addUserToSession' TypeError: Cannot read property 'completed' of undefined(…) TypeError: Cannot read property 'completed' of undefined
futureRobin
  • 81
  • 2
  • 10
  • I don't know if this is the only problem, but the server doesn't have access to `Session`, so creating a shared (client/server) method that uses session variables won't work. – David Weldon Dec 20 '15 at 21:29
  • 1
    Flow-router doesn't wait on subscriptions so it's likely your `Sessions` collection isn't loaded when you're trying to do the `findOne()`. See https://meteorhacks.com/flow-router-and-subscription-management – Michel Floyd Dec 21 '15 at 02:07
  • @DavidWeldon thanks for that :) – futureRobin Dec 21 '15 at 13:19

0 Answers0