I am developing app using firebase, and I want to make if a user login using a device, then if other devices should be logged out. how to do that ? can I track it based on their FCM token ? I have no idea how to do it
2 Answers
I had a similar problem and I solved it doing this:
on every sign in I get the device Mac Address and store it in the database for each user. when the user logs in for the first time the field will be null, otherwise, it will contain a value( the mac address).
for each login check the database for mac address for that user, and handle those cases:
1- when the user has a mac address you can check it vs the device mac address if it equal then it's the same device, and let him in.
2- if the mac address stored is different then he is already logged in from another device, you need to log him out from the other device then store the current mac address. and log him in.
this should be enough to give you an idea of what to do.
I hope this is helpful.
- 1,324
- 1
- 10
- 21
-
1How do you ensure that a malicious user doesn't just reverse engineer your application code. and passes the same value of the MAC address every time? – Frank van Puffelen Jul 25 '20 at 23:40
-
I don't. it has to be server-side. but that's the only (easy) thing I could think of by then. I am just fresh developer :). please let us know what is the best way to achieve this – Remon Shehatta Jul 25 '20 at 23:45
The FCM token is not unique per device it could change that's why there's onTokenRefresh
Im thinking of a way to do this by storing the user's uuid in firebase database with Boolean value and also the fcm token
USERUUID:
loggedIn : true
Token : his_fcm_token
And whenever user logins you check his flag if it's already true means he's logged in on another device
Use his fcm and send that old device a data notification to logout And then update fcm token in the database to the new device's token.
- 578
- 3
- 9