Meteor useraccounts watch state

27 Views Asked by At

I'm using Meteor useraccounts:bootstrap. On my navbar i have btnLogin and btnLogOut. I want only my login button to show when im logged out, and only the logout button when im logged in.

My logic:

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

How do i get my app to look for state without triggering an event/click?

Thank you!

1

There are 1 best solutions below

1
blueren On BEST ANSWER

If you're logged in, Meteor.userId() will return the _id of the current user.

So you can have something like this:

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;
     }
});