I have tried this a couple different ways and they both behave the same way (see below for code). I\'m using a spacebars if condition (and tried using a helper as well) to check
You can use instead, the currentUser
helper from accounts package, like this.
{{#if currentUser}}
{{else}}
{{> login }}
{{/if}}
Iron Router Option.
There is also a solution in the router level, using Router.onBeforeAction
.
// lib/routes.js
// Create the function to check login.
var requireLogin = function() {
if (! Meteor.user()) {
this.render('login');
} else {
this.next(); //using this.next the iron router will render the route named on the onBefore
}
}
Router.onBeforeAction(requireLogin, {only: 'theRoute});
UPDATE
Template.headerTpl.helpers({
isLogged:function(){
if(Meteor.user()){
return true;
}else{
return false;
}
}
})
{{#if isLogged}}
Welcome User
{{else}}
- Login
{{/if}}