Meteor: "ReferenceError: myAdminHookFunction is not defined"

Meteor: "ReferenceError: myAdminHookFunction is not defined"

正在关注 Matthew Platts 的 Meteor Tutorial

第4章第4.2.5 Force Login节,当我实现代码时,出现如下错误:

Your app is crashing. Here's the latest log.


/Users/TXC/.meteor/packages/meteor-tool/.1.1.3.1wysac9++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
                        throw(ex);
                              ^
ReferenceError: myAdminHookFunction is not defined
    at app/both/router.js:31:23
    at app/both/router.js:33:3
    at /Users/TXC/code/foosboom-meteor/.meteor/local/build/programs/server/boot.js:222:10
    at Array.forEach (native)
    at Function._.each._.forEach (/Users/TXC/.meteor/packages/meteor-tool/.1.1.3.1wysac9++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
    at /Users/TXC/code/foosboom-meteor/.meteor/local/build/programs/server/boot.js:117:5
Exited with code: 8
Your application is crashing. Waiting for file change.

UPDATE:一切正常,直到我按照 Listing 4.26: both/router.js.

中的建议更新代码

更新 2:这里是 router.js 文件的内容:

Router.configure({
  layoutTemplate: 'layout',
  loadingTemplate: 'loading'
});

Router.route('/', {
  name: 'games',
  waitOn: function(){
    return [Meteor.subscribe("games"), Meteor.subscribe("teams")];
  }
});

Router.route('/teams', {
  waitOn: function(){
    return Meteor.subscribe("teams");
  }
});

var requireLogin = function(){
  if(!Meteor.user()){
    if(Meteor.loggingIn()){
      this.render("loading");
    } else {
      this.render("accessDenied");
    }
  } else {
    this.next();
  }
}

Router.onBeforeAction(requireLogin);

我检查了我的代码 3 遍,但没看出哪里出了问题:有什么想法吗?

该教程中似乎有错字:

Router.onBeforeAction(myAdminHookFunction, {
 only: ['admin']
 // or except: ['routeOne', 'routeTwo']
});

应该是这样的:

Router.onBeforeAction(requireLogin, {
 only: ['admin']
 // or except: ['routeOne', 'routeTwo']
});

所以 myAdminHookFunction 应该替换为 requireLogin