I am working through the discovermeteor book by Tom and Sacha. To learn things better I am trying out various things in another toy application (other than Microscope).
I have the following package settings:
mrt remove autopublish
mrt add accounts-ui
mrt add accounts-password
In a file called main.js in the client folder, I added the following code:
var userobj = Meteor.user();
console.log("User object: ", userobj)
The userobj comes up as undefined. The user is logged in and I can access the user in the Templates using currentUser. For example, the code
{{#if currentUser}}
<div>You are logged in.</div>
{{else}}
<div>You should Log in.</div>
{{/if}}
in main.html, adds "You are logged in." to the page.
My question is, why is Meteor.user() returning undefined in the main.js file. Is there a way for me to access Meteor.user() in the js files and condition code on whether the user is logged in, in the js files.
Thank you.
Thanks to the Meteor creators. I really hope to use it for some real projects.