Meteor 用户帐户监视状态

Meteor useraccounts watch state

我正在使用 Meteor useraccounts:bootstrap。 在我的导航栏上,我有 btnLogin 和 btnLogOut。我只想在我注销时显示我的登录按钮,而在我登录时只显示注销按钮。

我的逻辑:

if (!error) {
    if (state === "signIn") {
      document.getElementById('btnLogin').style.display = 'none';
    }
    else if (state != 'signIn') {
      document.getElementById('btnLogOut').style.display = 'visible';
    }

如何让我的应用在不触发 event/click 的情况下查找状态?

谢谢!

如果您已登录,Meteor.userId() 将 return 当前用户的 _id。

所以你可以有这样的东西:

page.html:

{{#if isUserLoggedIn}}
      <<<<<show logout button >>>>>>
{{else}}
      <<<<<show login button >>>>>> 
{{/if}}

page.js

Template.page.helper({
     isUserLoggedIn: function(){
           if(Meteor.userId()){
                return true;
            }
          return false;
     }
});