Since upgrading to Meteor 1.3, I’ve had a bit of a problem getting the user’s profile in template.autorun. Here’s my code:
Template.dashboard.onCreated(function() {
var self = this;
self.autorun(function() {
var orgId = Meteor.user().profile.currentOrg;
self.subscribe('tasks', orgId);
});
});
And here’s the error:
Exception in defer callback: TypeError: Cannot read property 'profile' of undefined
at .<anonymous> (http://localhost:3000/app/app.js?hash=bbf512fa5c5ae71422836031aeccf663a1243196:5826:30)
at http://localhost:3000/packages/blaze.js?hash=38069f4f7cfbd8898160bc97d37dd847cd5985fe:1865:20
at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=38069f4f7cfbd8898160bc97d37dd847cd5985fe:3677:12)
at http://localhost:3000/packages/blaze.js?hash=38069f4f7cfbd8898160bc97d37dd847cd5985fe:1863:29
at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?hash=38069f4f7cfbd8898160bc97d37dd847cd5985fe:2204:12)
at viewAutorun (http://localhost:3000/packages/blaze.js?hash=38069f4f7cfbd8898160bc97d37dd847cd5985fe:1862:18)
at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?hash=b267c37effdf4af331d16fc647c0370c2eaff44d:341:36)
at new Tracker.Computation (http://localhost:3000/packages/tracker.js?hash=b267c37effdf4af331d16fc647c0370c2eaff44d:229:10)
at Object.Tracker.autorun (http://localhost:3000/packages/tracker.js?hash=b267c37effdf4af331d16fc647c0370c2eaff44d:580:11)
at Blaze.View.autorun (http://localhost:3000/packages/blaze.js?hash=38069f4f7cfbd8898160bc97d37dd847cd5985fe:1875:22)
Why would Meteor.user() be undefined?
If I refresh, I can get the page to render normally, but this makes me a little nervous to push it to production. Any ideas?