Hope everyone is doing fantastic!
So, I am in this situation where this has happened to me personally.
We are building an app, where we are making it offline-first. Once I have signed in using Google credentials, the app can work in an offline mode.
Based on https://stackoverflow.com/a/46674020/379235 answer, we were not waiting for the operations to resolve on the backend which makes it work in offline mode.
But then, the other day I was on my laptop and changed my Google password (but this situation can happen with any Social Login Password change). Then, a few hours later, I was using my app in offline mode (on my mobile) and showing success notification whenever the data was added.
But when I came online and reloaded the page (read reload again, because in Safari even if you add the app to Home Screen, every tap loads it as a new session), I saw nothing and assumed everything was fine, but it wasn't.
So what happened?
When the page reloaded, Firestore failed to get access as the Security Rules didn't allow it to read/write the data.
With this, as a user, my transactions were lost without me knowing about it. Also, when Firestore exception happened while writing the local data to the backend, as an app developer I also lost the access of those pending transactions that were supposed to be stored at the backend.
To reiterate, the sequence of operations where it occurred was
- User comes to the app and added to Home Screen on their mobile app.
- User signs in to the app using Google login (they also have the option to do that using Facebook and Twitter). The app uses Firebase Auth behind the scene.
- The user goes offline.
- The user continues to add the data and app shows success notifications (based on the local writes, guidance from here)
- The user gets access to the network on some other device and changes their Google password (this is the same Google login they have used to in step 2)
- The user continues to use the app in offline mode and add more data. The user comes back online and taps on the app icon (in iOS Safari, it is a page reload).
- The user observes that their data was not synced to the server.
- Behind the scene when step 7 happened -
- The Firestore tried to sync the data and failed on the Security rules (since step 5 has happened).
- The exception is logged on the console and the app lost the access to the pending data which were supposed to sync to the backend.
With that, my questions are following
- How can I handle the situation when the user is working with an app in offline mode, but their password (Google, Facebook, Twitter) has changed, which is used to sign-in into this app?
- How can I preserve their data and sync with backend once they have logged in again to the app with their changed credentials?
Thank you