简体   繁体   中英

Meteor Accounts.onLogin infinite loop

In the Meteor forums I read that it is suggested to put Meteor.logoutOtherClients inside 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. 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.

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.

You can also see the details reported here: https://github.com/meteor/meteor/issues/8669

This is a confirmed bug #8669 . So my workaround is I created a manual token for the user instead of using the default from accounts-base . I also handled the checking manually so basically getting rid of "magic" Meteor offers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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