I am using Firebase Realtime Database in my app. It works really well and I am quite satisfied with it. But recently I bumped into an edge case because of which some of my users are losing their data.
SCENARIO #1
The user logs into the app (Firebase Authentication) with internet connection on, and adds some data to the database.
The user signs out with internet connection on, and signs in again and the previously stored data is there as expected. The internet connection was available and the data got synced to the server.
SCENARIO #2
Now the user turns off his/her internet connection. Add some more data to the database and signs out of the app when the internet connection is off.
Now the user turns his/her internet connection back on and signs into the app in the exact same way as above.
Now the user does not see any data that was added while the app was in offline mode. I have setPersistenceEnabled(true)
and it works perfectly in normal situations.
The Problem
The problem is that persistence fails when the user is in offline mode, adds some data to the database (which does not sync to the server as there is no internet) and signs out in offline mode itself and then signs in again later.
This is an edge case but some of my users have faced this and have lost their valuable data because of this bug. How to fix this? Is it the default behavior of Firebase Database? If so, is there any workaround for this?