I’m trying to implement Meteor.logoutOtherClients()
I’m not sure where to put it… for the moment, I put it in an autorunblock in my Template.frontend.created:
Accounts.onLogin ->
Meteor.logoutOtherClients()
And it works - but not always… Sometimes it just seems to ignore the call?
How to detect a user was logged out? I saw this thread, but I would assume there was some call for this, or a surefire way. Because if someone lost their internet connection, this would aslo fire?
Did anyone implement this in a 100% effective way?
Accounts.onLogin doesn’t need to be called in your Template; you can call it anywhere. Meteor.logoutOtheClients can only be called client side however. So instead of putting this within an autorun in your Template, you could just define a file like accounts.js and make it available client side. So something like:
thank you for your response! I moved the logoutOtherClietns to a separate file and that seems to work (better). But the onLogout callback seems to work only if somebody actually logs out “manually”. What logoutOtherClients seems to do is more cut a client off. I can see a loss in connection with Meteor.status().connected, but that is also true if someone’s internet connection drops for a few seconds, so that does not work as expected. I was hoping there would be some way o actively tell a client they are being disconnected because of the double login, but for the moment there does not seem to be a way…
Thanks for the pointer on the first issue though; that allready helps
I’ve added logoutOtherClients() inside Accounts.onLogin() the problem is onLogin() gets called without end when multiple tabs are open. Is this the expected behaviour?