简体   繁体   English

流星Accounts.onLogin无限循环

[英]Meteor Accounts.onLogin infinite loop

In the Meteor forums I read that it is suggested to put Meteor.logoutOtherClients inside Accounts.onLogin() . 在Meteor论坛中,我读到建议将Meteor.logoutOtherClients放在Accounts.onLogin() Although this works, there is a problem to it, and that is the Accounts.onLogin() gets called multiple times when there are multiple TABS (not browsers) opened. 尽管这可行,但存在一个问题,那就是当打开多个TABS(而非浏览器)时, Accounts.onLogin()被多次调用。 Is this the expected output? 这是预期的输出吗?

Here is my code below: 这是我的代码如下:

Accounts.onLogin(() => {
  console.log('onLogin called')
  Meteor.logoutOtherClients((error) => {
    if (error) {
      console.log(`error: ${error.error}`)
    }
  })

  // Some Meteor Method calls here
  alert('Welcome User!')
})

Another problem is that I got method calls in the same Accounts.onLogin() block and it gets called every time. 另一个问题是我在同一Accounts.onLogin()块中获得了方法调用,并且每次都调用它。

meteor@1.4.2.6
accounts-base@1.2.17

Question

  1. How should I prevent this infinite calls from happening? 我应该如何防止这种无限呼叫的发生?
  2. If I can't prevent this, where should I dispatch method calls when user logs in? 如果无法阻止,那么用户登录时应该在哪里调度方法调用? Because obviously if I put it inside this code block it causes the dispatches to get called infinitely and that alert gets fired infinitely. 因为很显然,如果我将其放在此代码块中,它将导致调度被无限调用,并且该alert将被无限触发。

You can also see the details reported here: https://github.com/meteor/meteor/issues/8669 您还可以在此处查看报告的详细信息: https : //github.com/meteor/meteor/issues/8669

This is a confirmed bug #8669 . 这是一个已确认的错误#8669 So my workaround is I created a manual token for the user instead of using the default from accounts-base . 所以我的解决方法是我为用户创建一个手动令牌,而不是使用accounts-base的默认令牌。 I also handled the checking manually so basically getting rid of "magic" Meteor offers. 我还手动进行了检查,因此基本上摆脱了“魔术”流星的报价。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM