There is nice feature when working in offline mode with Firestore
:
Cloud Firestore supports offline data persistence. This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data. When the device comes back online, Cloud Firestore synchronizes any local changes made by your app to the Cloud Firestore backend.
But what I really need is the same thing: once the user is logged in, in any way (anonymously or using some provider), that all data they created uploads to Firestore.
I ask this because let's say anonymous login is failing or any login is failing, and I need the UID to connect user with his data. I guess this is a realistic scenario, probably very rare, but it can happen.
Is there something in the Firebase API that solves this?
If you are trying to store per-user data in Firestore, you definitely need a UID in order to collect that data in a path that makes sense for that user. You can't reasonably write per-user data without one.
If you are allowing the user to use your app without first signing in, it makes sense to silently and automatically sign them in with anonymous authentication. This will create an account with a UID that you can use to write documents to Firestore.
When it comes time to sign in the user with whatever real user auth provider you choose, you can upgrade the anonymous account by linking it to the authentication provider. All of their existing data in Firestore will remain unaffected.