Accounts.onLogin抛出会话未找到错误

时间:2017-10-03 17:59:08

标签: meteor exception-handling url-redirection meteor-accounts flow-router

LoggedInUser可以正常运行,但只要应用程序启动并且查询URL就像尝试登录或导航到任何其他URL一样,Accounts.onLogin会引发以下错误。我不知道可能是什么原因。

var LoggedInUser = FlowRouter.group({
  name: 'currentUser', triggersEnter: [function () {
    if (!Meteor.loggingIn() || !Meteor.userId()) {
      var currentRoute = FlowRouter.current();
      if (!currentRoute.route.name === 'home') {
        console.log(currentRoute.path);
          Session.set('redirectAfterLogin', currentRoute.path);
      }
      FlowRouter.go('home');
    }
  }]
});

Accounts.onLogin(function () {
  let redirect = Session.get('redirectAfterLogin');
  if (redirect) {
    if (redirect != 'home') {
      FlowRouter.go(redirect);
    }
  }
});

cmd控制台上的错误

I20171003-18:28:44.913(1)? Exception in onLogin callback: ReferenceError: Session is not defined
I20171003-18:28:44.919(1)?     at lib/routes/routes.js:30:18
I20171003-18:28:44.921(1)?     at runAndHandleExceptions (packages\callback-hook.js:152:24)
I20171003-18:28:44.926(1)?     at packages\callback-hook.js:159:12
I20171003-18:28:44.931(1)?     at packages/accounts-base/accounts_server.js:164:5
I20171003-18:28:44.934(1)?     at [object Object]._.extend.each (packages\callback-hook.js:128:15)
I20171003-18:28:44.938(1)?     at AccountsServer.Ap._successfulLogin (packages/accounts-base/accounts_server.js:163:21)
I20171003-18:28:44.943(1)?     at AccountsServer.Ap._attemptLogin (packages/accounts-base/accounts_server.js:353:10)
I20171003-18:28:44.946(1)?     at [object Object].methods.login (packages/accounts-base/accounts_server.js:530:21)
I20171003-18:28:44.949(1)?     at packages\check.js:128:16
I20171003-18:28:44.953(1)?     at [object Object].EVp.withValue (packages\meteor.js:1135:15)

1 个答案:

答案 0 :(得分:0)

您使用的onLogin函数根据以下行需要Session程序包:

  let redirect = Session.get('redirectAfterLogin');

找不到控制台状态中的错误,而不是Session软件包。请确保以下几点:

  1. 流星会话已安装。如果没有,请安装:

    meteor add Session
    

在终端的项目文件夹中。

  1. 会话已导入到您要使用的文件中,如果没有,请在文件顶部添加:

    import { Session } from 'meteor/session'