Exception in template helper returning user-document-data


#1

Hi,

I have a custom field “customData” in my user document.
I keep getting an exception in my client-console regarding this template helper although the data is showed correctly.

template.x.helpers({
  customData: function() {
    return Meteor.users.findOne().customData;
  }
});

what is causing this “issue”? I appreciate any input.


#2

Meteor.users is reactive and your helper is probably called more than once. I bet Meteor.users.fondOne() returns null at one of the calls


#3

how would you resolve that issue?


#4
template.x.helpers({
  customData: function() {
    var user = Meteor.users.findOne();
    return user ? user.customData : null;
  }
});