Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only one log in per user at the time in Firebase for android

I want users to use their credentials on one device at the time, avoiding multiple log ins with the same email and password. I´ve found this from firebase official site but it is not related with what I am trying to do.

like image 703
Fran Tardencilla Avatar asked Feb 11 '18 13:02

Fran Tardencilla


1 Answers

There is no way to prevent a user from authenticating on multiple devices. In fact: to know that the same user is on two devices, they'll need to authenticate on both devices.

Depending on the back-end service that you're using, it may be possible to only allow resources to be accessed from one device.

For example, if your app uses the Firebase Database, you could write the InstanceID token into the database when the user logs in. And then only allow the write if there is no token yet, or the token matches the token that last logged in. You could then even warn the user if they log in on a second device, that they're already accessing the system from another device and should log out there first.

But this is all wrought with problem cases.

For example: when do you flag that a user stopped using your app on one device (i.e. delete the InstanceID token from the database)? When they log out? That means they'll have to log in every time they want to use the app, a type of friction most users don't like much.

Or will you try to automatically detect that they stopped using the app, e.g. when it goes into the background? What happens if you miss that moment because of a bug, a crash, or a network glitch? Will the user then be unable to use the app from their other device?

For these and many more reasons I usually recommend against such a single-device policy: it's more trouble than it's worth.

Also see:

  • How to handle multiple connections of the same user on Firebase?
  • How to prevent simultaneous logins of the same user with Firebase?
like image 165
Frank van Puffelen Avatar answered Sep 17 '22 22:09

Frank van Puffelen