title: Meteor.user() is undefined inside a function
body: <p>I have this template helper</p>
  
  <pre><code>Template.foo.helpers
    'bar':-&gt;
      console.log(Meteor.user().profile)
    'baz':-&gt;
      console.log(Meteor.user().profile)
    'buzz':-&gt;
      console.log(Meteor.user().profile)
  </code></pre>
  
  <p>And it logs the user object flawlessly.</p>
  
  <p>But when I try to use it outside of the template helper it returns an <code>Uncaught TypeError: Cannot read property 'profile' of undefined</code></p>
  
  <p>Like this</p>
  
  <pre><code>checkProfile=(profile)-&gt;
    console.log profile
  
  Template.foo.helpers
    'bar':checkProfile(Meteor.user().profile)
    'baz':checkProfile(Meteor.user().profile)
    'buzz':checkProfile(Meteor.user().profile)
  </code></pre>
  
  <p>I think that it executes the function before the Meteor.user() is loaded but when I try to log <code>Meteor.userId</code> inside the checkProfile, ex:</p>
  
  <pre><code>checkProfile=(profile)-&gt;
    console.log Meteor.userId()
    console.log profile
  </code></pre>
  
  <p>even</p>
  
  <pre><code>checkProfile=(profile)-&gt;
    console.log Meteor.userId()
    console.log(Meteor.user())
  </code></pre>
  
  <p>It logs the userId asap but still returns an uncaught error.</p>
  
  <p>Now I concluded that <code>Meteor.userId()</code> is always available at the start of meteor and <code>Meteor.user()</code> object is loaded after?</p>
  
  <p>Please literate me for this conclusion as these little things may become a big problem in my code in the future. Thanks. </p>
  
  <p><strong>Side Note:</strong></p>
  
  <p>I'm sure that the user is logged in because I'm testing error tests when the user is loggedIn. It's just when the page refreshes, the code runs and returns that error when it tries to run Meteor.user()</p>