Search code examples
javascriptmeteoriron-router

Confused About Meteor this.next() Error onBeforeAction


I have the following code for a Router map:

this.route('confirmTag', {
    path: '/confirm-tag',
    template: 'confirmTag',
    controller: 'SignUpController',
    onBeforeAction: function () {
        if (Meteor.user()) {
            if (typeof user.profile.tag === 'undefined') {
                Router.go('confirm');
            } else {
                Router.go('checkEmail');
            }
            this.next();
        } else {
            Router.go('signUp');
        }
        this.next();
    }
});

Yet, I keep getting this error in console:

Exception in callback of async function:
.onBeforeAction@http://localhost:3000/lib/router.js?783dc96a24a92cfd09fbf0ca371d762661a830bb:87:9

Line 87 in the example code is:

if (typeof user.profile.tag === 'undefined') {

What or how should "this.next();" be placed in the above code?

Thanks in advance.


Solution

  • I don't see user defined anywhere. What about ...

    this.route('confirmTag', {
        path: '/confirm-tag',
        template: 'confirmTag',
        controller: 'SignUpController',
        onBeforeAction: function () {
            if (Meteor.user()) {
                var user = Meteor.user();
                if (typeof user.profile.tag === 'undefined') {
                    Router.go('confirm');
                } else {
                    Router.go('checkEmail');
                }
                this.next();
            } else {
                Router.go('signUp');
            }
            this.next();
        }
    });