Meteor template: What's the simplest way to check if a user is logged in?

Alveoli picture Alveoli · Apr 29, 2015 · Viewed 8.6k times · Source

I'm using Meteor's accounts-ui. Is there a way to check if the user is logged in on the template without writing custom helper code?

Pseudo code:

{{#if userIsLoggedIn }}
    You're logged in
{{/if}}

If not, what's the cleanest, most idiomatic way of doing it?

I only care about client-side here.

Thanks.

Answer

SylvainB picture SylvainB · Apr 29, 2015

Simple answer: check if the currentUser object exists.

{{#if currentUser }}
  You're logged in
{{/if}}

Yes, it is a default helper, no need to write anything else!