How to use Meteor.logoutOtherClients()?


#1

I want to set permission for one user can be login only one at the same time (from many browsers).
So I should use this method, or have any solution?
Now I use iron-router, and use Router.onBeforeAction() to check.
How to use Meteor.logoutOtherClients()?


#2

I think what you want is to run Meteor.logoutOtherClients() when the user logs in, like this:

Accounts.onLogin(function () {
    Meteor.logoutOtherClients();
});

#3

I tried, but don’t work.

Accounts.onLogin(function () {
    Meteor.logoutOtherClients(function(){
       Router.go('/');
   });
});

#4

What does not work? Is the problem consisting of other clients not being logged out or the router not going to the correct URL?


#5

If you do:

Accounts.onLogin(function () {
    Meteor.logoutOtherClients(function(error){
       console.log(error);
       Router.go('/');
   });
});

do you get any error logged?


#6

I get error undefined, when I login the first time with Chrome. after that I login with the same user on Firefox, I still get error undefined, but the first on Chrome don’t work. It can’t logout, can’t get or insert data … and Router.go('/') don’t work. On the other hand the second on Firfox is work fine.


#7

Now I understand about this, but why it run on the first time for login.
I thinks that it should be run when the second of user login (have one online).


#8

It has to always run to find out if there are any other clients logged in anyway.