Hi,
I have an exception in my console when I reload the user account page where I want to load all the post of the current user. I guess that it’s due to the asynchronous call to my filter or something like that but I don’t understand how to manage this issue. Because finally my page is loaded like I want but I still have the error in the console…
My router :
`var connectedFilter = function () {
if (!Meteor.user()) {
this.render('notFound');
this.stop();
}
else {
this.next();
}
};
Router.route('/account', {
name: "userProfile",
template: "userProfile",
before: connectedFilter,
waitOn: function() {
var username = Meteor.user().username;
return Meteor.subscribe("userPost", username);
},
data: function(){
var username = Meteor.user().username;
var Posts = CPDM.find({author:username}, {});
return {
Posts: Posts
};
}
});`
The error in the console is this one :
Exception in callback of async function: TypeError: Cannot read property 'username' of undefined
at waitOn (http://localhost:3000/app/app.js?hash=7b68a15d92da3bfa36869301f6641c97a3c7946d:1722:41)
at http://localhost:3000/packages/iron_router.js?hash=e3e6958b865eb45fe4a72dcf55ec06d87881d90b:435:22
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?hash=27b3d669b418de8577518760446467e6ff429b1e:149:11)
at RouteController._runRoute (http://localhost:3000/packages/iron_router.js?hash=e3e6958b865eb45fe4a72dcf55ec06d87881d90b:434:5)
at Function.Route.dispatch (http://localhost:3000/packages/iron_router.js?hash=e3e6958b865eb45fe4a72dcf55ec06d87881d90b:850:18)
at route (http://localhost:3000/packages/iron_router.js?hash=e3e6958b865eb45fe4a72dcf55ec06d87881d90b:707:11)
at boundNext (http://localhost:3000/packages/iron_middleware-stack.js?hash=a144d30621d65956143c8d952f54d0082094915f:418:31)
at http://localhost:3000/packages/meteor.js?hash=ae8b8affa9680bf9720bd8f7fa112f13a62f71c3:1105:22
at boundNext (http://localhost:3000/packages/iron_middleware-stack.js?hash=a144d30621d65956143c8d952f54d0082094915f:365:14)
Thank’s for helping !