I am using the following path to logout in iron-router
Router.route('/logout',{
name: 'logout',
onBeforeAction: function(){
Meteor.logout(function(err){
console.log('logging out' + Meteor.userId());
Router.go('/');
});
}
});
which is used in many places in my app when it is triggered by:
Template._loginButtonsLoggedInDropdown.events({
'click #login-buttons-logout': function (event) {
event.preventDefault();
Router.go('/logout');
}
});
It works fine everywhere but it fails to logout from one template;actually is logs out but after 20secs or so; this specific template has 3 reactive template's vars and 2 subscriptions defined in .onCreated function. I am looking for any hints why it is so slow and if i should close the template or subscriptions in other way? or any other reason why it logs out so slowly..
version without routers works the same (meaning logout still takes 20sec)
'click #login-buttons-logout': function (event) {
event.preventDefault();
Meteor.logout(function(err){
console.log('logging out' + Meteor.userId());
Router.go('/');
});
}
the problem was my subscription although I do not fully understand why.
My code was:
Template.observedQuestions.onCreated(function(){
var self = this;
self.autorun(function(comp){
self.subscribe('observedQuestionsFeed');
});
});
which i then changed to:
Template.observedQuestions.onCreated(function(){
computation = Tracker.autorun(function(thisComp){
status = Session.get('loggingOut');
console.log('tracker started ' + status);
mySubscription = self.subscribe('observedQuestionsFeed');
if (status){
thisComp.stop();
}
});
});
where I do stop the computation manually and it works.
thank you all for your help.