Search code examples
meteoriron-router

"Object is not a function" in a Meteor route


I just created two routes that work just fine, but I'm getting an odd error in the console that I would like to fix.

Exception in callback of async function: TypeError: object is not a function at OnBeforeActions.loginRequired (http://localhost:3000/client/router/config.js?8cea1a53d7ab131377c2c4f91d534123cba79b70:12:20)

This error shows up every time I visit the same page.

This is my config.js file:

Router.configure({
    layoutTemplate: "uMain"
});

var OnBeforeActions = {
    loginRequired: function (pause) {
        "use strict";
        if (!Meteor.userId()) {
            this.render("uLogin");
            return pause();
        } else {
            this.next();
        }

    }
};

Router.onBeforeAction(OnBeforeActions.loginRequired, {
    except: ["uLogin"]
});

The idea is to redirected all user who are not logged in to "uLogin". It works (or I haven't found any bugs so far).

What am I doing wrong?


Solution

  • You can see the line where you have the error in developers console when you click on link http://localhost:3000/client/router/config.js?8cea1a53d7ab131377c2c4f91d534123cba79b70:12:20 in your console.

    Your problem is that new Iron Router does not use pause() anymore. Remove pause from your onBeforeAction.

    Developers console is your good friend. Learn how to use it.