How to prevent same user logging in from different devices ? My app is paid , so I dont want credentials to be shared

后端 未结 2 840
时光说笑
时光说笑 2021-01-28 22:55

I am new to firebase , but I managed to develop an app using firebase -email&password authentication This app is for an organization\'s members so there is no sign up on th

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-28 23:16

    You can employ a session manager, which just keeps track of the last session and terminates all other sessions for that user. A simple way to accomplish this is to generate a UUID (random 128-bit value) on the client every time your app launches and call it sessionId. If the user is logged in, or when the user logs in, write that sessionId to the database under the current user's userId in a field called lastSessionId. Then just listen for changes to lastSessionId (on the client) for the current userId.

    When another client launches your app using the same userId, that client is also given a random sessionId and that sessionId is also written to the database under that userId (overriding the last client's write). All of the clients logged into that userId are then notified of the change to lastSessionId (through the document listener) and for every client where the local sessionId does not match the remote lastSessionId, their UX is handled accordingly. You can gracefully sign those clients out or more brutally terminate their app with some sort of fatal error.

提交回复
热议问题