functions-samples icon indicating copy to clipboard operation
functions-samples copied to clipboard

Fixed onDisconnect logic to use deviceId

Open maneesht opened this issue 3 years ago • 0 comments

The example originally used uid documents to determine whether a user is online or not. This is not best practice because you may have an onDisconnect that sets the user as offline, and if the same user open two different tabs, close one tab, and the user would show up as offline, even though one tab is still open.

This PR adds a devices collection and then adds a new document that represents the device's ID, and onDisconnect, will set the device's status to offline. The coThe function will check that change and remove the device from the Firestore user's devices collection and check if there are no devices in the collection. If that is the case, then the user itself will be removed from the user collection.

The client will then check Firestore for how many users are in the users collection.

maneesht avatar Aug 29 '22 22:08 maneesht