I am building an app in Meteor. I am trying to pass a user object into a template, but the console keeps printing out "user undefined" although I clearly define the user object in my controller:
controller.js:
checkoutController = RouteController.extend({
waitOn: function () {
var sessionId = Session.get('sessionId');
Meteor.subscribe('cartItems', sessionId);
Meteor.subscribe('userProfileExtended2');
},
data: function(){
return {
user: Meteor.users.findOne(this.params._id) //user defined
};
},
action: function() {
this.render('Checkout');
console.log('user:')
console.log('user: ' + user);
}
});
My publish.js, which publishes the user object:
//this is for a user to edit his/her own profile since there's no admin check
Meteor.publish('userProfileExtended2', function(userId) {
if(!this.userId) return null;
var currUser = Meteor.users.find(this.userId);
//need to add logic to make sure user can only edit his/her account
console.log('user searched for from userprofileextended2 is ' + this.userId);
return Meteor.users.find(this.userId);
});
Here is my route:
Router.route('/checkout', {name: 'Checkout', controller: 'checkoutController'});
Notes:
1) My terminal console prints out the user Id correctly 2) My browser console prints out "ReferenceError: user is not defined"
Any thoughts? Thank you in advance!
data:function(){ user = Meteor.users.findOne(this.params._id)}