meteor - How to redirect after user has just logged in or just logged out -
it seems deps.autorun way go router.go doesn't seem work within deps.autorun.
here example 3 routes: index
, signin
, dashboard
:
router.configure({layouttemplate: 'layout'}); router.map(function() { this.route('index', {path: '/'}); this.route('signin'); this.route('dashboard'); }); var mustbesignedin = function(pause) { if (!(meteor.user() || meteor.loggingin())) { router.go('signin'); } else { this.next(); } }; var gotodashboard = function(pause) { if (meteor.user()) { router.go('dashboard'); } else { this.next(); } }; router.onbeforeaction(mustbesignedin, {except: ['signin']}); router.onbeforeaction(gotodashboard, {only: ['index']});
if user on index
page , logged in, automatically routed dashboard
page. on page except signin
, if user not logged in routed signin
page. onbeforeaction
reactive these rules enforced if user logs in or out.
of course routes different, example illustrates 1 way make work iron-router.
also see using hooks section of iron-router guide.
Comments
Post a Comment