Meteor takes time to know if there's a {{currentUser}} or not -
Meteor takes time to know if there's a {{currentUser}} or not -
i've few code want run when there's nouser
, few when there's currentuser
. these within navigation template. so...
{{#if currentuser}} <li class="nav"><a href="{{pathfor 'create'}}">post</a> </li> <li class="nav"><a>ola, {{thisuser}}!</a> </li> <li class="nav"><a href="#" id="logout">log out</a> </li> {{/if}} {{#if nouser}} <li class="nav"><a href="{{pathfor 'signup'}}">sign up</a> </li> <li class="nav"><a href="{{pathfor 'login'}}">login</a> </li> {{/if}}
so problem when there's currentuser
(i.e, i'm logged in) , refresh page, code within {{#if nouser}}
block shows first {{#if currentuser}}
block, while {{#if nouser}}
block meant show when there no user. here's helper code template..
template.navigation.helpers({ thisuser: function () { homecoming meteor.user().username; }, nouser: function () { var user = meteor.user(); if (!user) { homecoming true; }; } });
don't know doing wrong here. :( please help.
you should utilize if else conditions instead of nouser helper. , prevent showing "nouser" block while logging in have utilize {{ loggingin }} helper. this:
{{#if loggingin}} <p>loggin in...</p> {{else}} {{#if currentuser}} <li class="nav"><a href="{{pathfor 'create'}}">post</a> </li> <li class="nav"><a>ola, {{thisuser}}!</a> </li> <li class="nav"><a href="#" id="logout">log out</a> </li> {{else}} <li class="nav"><a href="{{pathfor 'signup'}}">sign up</a> </li> <li class="nav"><a href="{{pathfor 'login'}}">login</a> </li> {{/if}} {{/if}}
because meteor not know whether user logged in or not. hence have utilize loggingin helper.
meteor meteor-blaze meteor-accounts
Comments
Post a Comment