12

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.

Alveoli
  • 1,202
  • 17
  • 29

1 Answers1

27

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!

SylvainB
  • 4,765
  • 2
  • 26
  • 39
  • Great - so easy if you know :D – Alveoli Apr 29 '15 at 13:32
  • 5
    Note: to check in your javascript if the user is logged in you can use `if (Meteor.user())` – phocks May 01 '16 at 06:00
  • Is there a React-way of knowing this? `Meteor.user()` is too expensive to call when required by multiple components. – JohnnyQ Feb 06 '17 at 09:07
  • Sadly, no. React being independent from the Meteor ecosystem, I guess you'll have to either build that logic yourself or find a third party that did. Welcome to the world of modularity, my friend – SylvainB Feb 06 '17 at 10:27