Is it possible to check for an unique client in meteor? This sounds a little strange. Let me explain it:
I want to let my meteor app only work at one computer at the same time. But I can't use the IP for checking, as there are also computers in a same network, so there would be the same IP for the external sever.
If somebody open the app on a second computer, all other (opened) app instances on other computer should be logged out (or something like this).
Is this technical possible in meteor?
Update
Please note that I don't want to block a second login, but I want to logout on all other devices if the user do a login.
meteor has in built function for this
please Check
Meteor.logoutOtherClients([callback])
Meteor Documentation
EDIT: I may have misunderstood the question, this is for making sure the user is only logged in at one device at a time. Not only one user at a time.
Not only is it possible, it's built in. Check out the docs
Call Meteor.logoutOtherClients()
on login to logout other clients logged in as the same user.
/client/lib/hooks.js
Accounts.onLogin(function () {
Meteor.logoutOtherClients(function (error) {
if (error) {
//Error handling goes here
console.log(error)
}
})
}
You need to use the Server callback validateLoginAttempt, and delete all the loginTokens from Meteor.users before logging in a user.
Example requires accounts-ui
and accounts-password
packages.
./single.html:
<head>
<title>SingleUserSystem</title>
</head>
<body>
<h1>Welcome to Meteor!</h1>
{{> loginButtons}}
{{> main}}
</body>
<template name="main">
<div id="name">
{{#if currentUser}}
<h1>Logged In!</h1>
<h3>Another user logging in will log you out.</h3>
{{else}}
<h1>Logged Out!</h1>
{{/if}}
</div>
</template>
./single.js:
if (Meteor.isServer) {
// Server Callback on all login attempts
Accounts.validateLoginAttempt(function(attempt) {
if (!attempt.allowed) // If login attempt was going to fail we
return false; // should not log out currently logged in user
// deleting loginTokens from Meteor.users collection logs out users
Meteor.users.update(
{},
{$set: { 'services.resume.loginTokens': [] } },
{multi: true}
);
return true; // return true to allow login to succeed
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With