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

1

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.

Christensen answered 29/4, 2015 at 13:22 Comment(0)
B
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!

Blueweed answered 29/4, 2015 at 13:24 Comment(4)
Great - so easy if you know :DChristensen
Note: to check in your javascript if the user is logged in you can use if (Meteor.user())Impute
Is there a React-way of knowing this? Meteor.user() is too expensive to call when required by multiple components.Soubise
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 friendBlueweed

© 2022 - 2024 — McMap. All rights reserved.