js noob here
So if a user is logged in and I attach return Meteor.user();
to isUser
helper and then add this html {{#if isUser}}
, it will evaluate to true.
Shouldnât isUser
return Object?
Youâre seeing the effect of âtruthyâ (and conversely âfalseyâ) values. http://james.padolsey.com/javascript/truthy-falsey/
Objects are âtruthyâ, in that they can be evaluated to a Boolean true
. Numbers are also truthy, except when theyâre equal to 0
or are NaN
. Empty strings are false
but non-empty strings are true
.
if
evaluates the truthiness of a statement. In this case, it is evaluating what is returned by Meteor.user()
. If the user is logged in it does return an (non-empty) object, which is then evaluated to true
. If it returned undefined
it would be evaluated to false
.
Thereâs more intricacies and gotchas to the whole topic that Iâm sure more experienced developers could go on about, but this should be enough for a basic understanding.
if the user is logged out, then if (Meteor.user())
will return false because it is undefined.
There already exists a global helper currentUser
which you can use to check/access the user (in this example requiring the user to have a profile object)
{{#if currentUser}}
{{currentUser.profile.name}}
{{/if}}