How to set the user login only one at the same time or check user online or not?


#1

I want to set the user can login only one at the same time.
For example, I have “theara” user account to login app. When I login on PC1 (online), so I can’t use the same user to login on PC2 (local network).
How to check user online or solve?


#2

Meteor already has a function for that:

http://docs.meteor.com/#/full/meteor_logoutotherclients


#3

Thanks but I don’t know how to use it.


#4

You just do Meteor.logooutOtherClients() on your login! What are you
confused about?


#5

I’m wondering if @theara means “prevent another login” rather than “log others out when I login”?


#6

What the prevent another login?


#7

Hm, it would be interesting and also blocking because due to connectivity or other intermittent issue a client may be known to the server as connected, therefore not allowing the user login at all from other places.

Perhaps one of the presence packages may help with such a scenario.


#8

Thanks for your explain, I will try to fine the presence package.


#9

Could you recommend for the popular package for this?


#10

Take a look at https://atmospherejs.com/tmeasday/presence and https://atmospherejs.com/mizzao/user-status


#11

I’m not sure there’s a user presence package that scales yet… Both of those look like they wouldn’t handle multiple app instances very well.


#12

The tmeasday package actually uses a dedicated collection to overcome scaling issues.


#13

While it does use a collection, this doesn’t fully mitigate the issues that are caused by scaling to multiple instances… The way it currently works, at start up it starts a function that runs every 5 seconds which checks for outdated presence records, then when the user signs in, it calls an updatePresence method and adds a new record to the presences collection. Then it calls a setInterval which calls a presenceTick method every 5 seconds that updates the collection with a new date… The notion is that when the user disconnects the tick stops, the server doesn’t get a tick so on the next check the connections presence record gets removed.

The problem here is that if an instance stops or dies for any reason, the logic that removes the records for those connections also stops and thus you are stuck with presence records that are no longer valid and the package reports users online that are not any longer…


#14

So perhaps a cleanup function that runs on a wider schedule, perhaps through one of the persisted job runners, could mitigate the problem.

I don’t see this as a scaling issue. It can just as well happen with a single instance, thus it is more like an architecture problem.


#15

I tried the mizzao:user-status with ian:accounts-ui-bootstrap-3.
Status set online is true (auto) when I login. how to check before login?
I thinks that it have problem when the user don’t logout but close the browser.