Iron route with login template

i’m making a app where you have to login to use it.

The problem is:

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

How to disable it so I only use the welcome template with the login form

The code below almost work, but it shows the welcome template and the mainLayout template

Router.onBeforeAction(function () {
  // all properties available in the route function
  // are also available here such as this.params

  if (!Meteor.userId()) {
    // if the user is not logged in, render the Login template
    this.render('welcome');
    
  } else {
    // otherwise don't hold up the rest of hooks or our route/action function
    // from running
    this.next();
  }
});

Sorry this isn’t an answer to your question.

I don’t know how much help you will find in the forums for using Iron Router.
That was the favourite a while ago - you’re best to swap out to using Flow Router.

This is what I do :slight_smile:

Router.configure({
  layoutTemplate: function(){
    return Meteor.userId() ? 'layout' : 'empty';
  }
});
<template name="empty">{{>yield}}</template>
2 Likes

It works perfect, thanks