iron router - Meteor.user() login issue -
i testing restrict login function router code below
var requirelogin = function() { if (! meteor.user()) { console.log("user not logged"); this.next() } else { console.log("user logged"); this.next() } } router.onbeforeaction(requirelogin, {except: ['home','login','about']});
when try enter restricted area userprofile
ask me log in , print "user not logged"
, after log in , try access area again. printing both code starts "user not logged"
, "user logged"
i want know how avoid happen? since page become glitched when happened.
i want print "user logged"
if enter restricted area page.
any appreciated.
you need integrate meteor.loggingin()
somewhere in requirelogin
function. because, what's happening meteor still loading user system , every route change, re-authenticates user based on current session, if exists.
var requirelogin = function() { if(!meteor.user()){ if(meteor.loggingin()){ this.render(this.loadingtemplate); }else{ this.render('accessdenied'); } }else { this.next(); } }
you notice uses this.loadingtemplate
. keep this, must configure routes have loading template. e.g.:
router.configure({ loadingtemplate: 'loading' });
or swap out this.render('loading');
'loading'
template name of 'now loading' yield/page.
Comments
Post a Comment