Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor.js - Check logged in status before render

First off lets just start with the fact that I am a complete noob with Meteor. Now that that is out of the way let the problem begin...

I have two pages, a splash page at '/' and a home page at '/home'. I am using iron-router for the routing. Now If I am not logged in and on the splash page and login I have it redirecting to the home page this works. Now if I close my browser and reopen and goto the '/' it loads for a few seconds then realizes that I am actually still logged in and then redirects me to '/home'.

My question is how to I get rid of this initial showing on the '/' when I am already logged in? I only want to show that page to people not signed in. Here is the code that I have in my router:

    Router.configure({layoutTemplate: 'mainLayout'});

Router.map(function() {
  this.route('splash', {path: '/'});
  this.route('home');
});

var mustBeSignedIn = function(pause) {
  if (!(Meteor.user() || Meteor.loggingIn())) {
    Router.go('splash');
    pause();
  }
};

var goToDashboard = function(pause) {
  if (Meteor.user()) {
    Router.go('home');
    pause();
  }
};

Router.onBeforeAction(mustBeSignedIn, {except: ['splash']});
Router.onBeforeAction(goToDashboard, {only: ['splash']});

Hope this helps.

like image 350
BobFranz Avatar asked Oct 20 '22 10:10

BobFranz


1 Answers

Using fast-render might be a solution. Just run

mrt add fast-render

Check this great article on this topic.

like image 190
Hubert OG Avatar answered Oct 23 '22 09:10

Hubert OG