iron-meteor / iron-router

A client and server side router designed specifically for Meteor.
MIT License
1.98k stars 413 forks source link

User get's logout after reloading a page #1504

Closed jakubjafra closed 8 years ago

jakubjafra commented 8 years ago

Hi,

I have an issue when using meteor and trying to reload current page (I use iron-router for routing). When I try to reload page using

window.location.reload();
// or
window.location = window.location;

The reload is happening but soon after (only in production, not at localhost) user gets logout. I think this is a bug. Is there any way to reload page without logout?

Or, maybe, there is a bug in my controllers in routing. There are configured as follows:

    RouteController.extend({
        onBeforeAction: function () {
            if(Meteor.user() !== null) {
                if(Roles.userIsInRole(Meteor.userId(), 'client'))
                    this.next();
                else
                    Meteor.logout();
            } else
                this.redirect('login');
        }
    })

Are there correct? Maybe when browser try to render new page the iron router calls Meteor.logout() due to some bug in here.

Cheers

chrisbutler commented 8 years ago

@khronedev your Meteor.logout() is probably getting called somehow, because reloading will re-run subscriptions/publications. you can use console.log() statements to check this

it's also better to check for a user with if (Meteor.userId()) because of reactivity and also the possibility that the user document hasn't been loaded on the client when this function is first run