Quick login / auto sync
arthurpaulino opened this issue · 5 comments
Hi there! We've been exchanging emails recently. I hope you're safe and healthy!
This is something that I've done before in an app that used Firebase: Direct (local) login. So, instead of relying on a response from Google API everytime, it's possible to allow the user to use the app as intended, even offline, and the SDK should take care of anything that should be saved and sent to the Firebase server. When the user accesses the app using wi-fi or 4g, the SDK just synchronizes automatically like magic.
The logic for this is somewhat coded here, from lines 37 to 50. Keep in mind that the code I linked is very old and I'm pretty sure that the API has changed since then!
Hmmm, it makes sense - so once a user is signed in with any method once, just calling the Firebase user sign in should populate the correct data, without needing to get the credentials from Google again?
I have to admit I tried fixing the offline use before, but failed to get it working exactly because of the logic process... Looks like this is what I had wrong before. Thanks!
Yes! Gmail app, for instance, lets you read previously stored emails and even write new ones offline without needing to sign in everytime. It just won't sync (download new emails or send the ones you write) if you're offline.
Cool, I was aware of that functionality, I just couldn't get it to work.
Unfortunately, I recently added a backend, using Firebase functions, and the app works against that as an API to get the user and characters at once. I'm assuming that won't just work out of the blue offline...
I have been thinking about adding a storage media cache for the character/user files so I can use them completely offline, and in the future that can be used as a no-login solution as well... I'll have to push that up.
For now, I think I have the user login working without going through Google every time, and also fixed some caching issues that caused it to not remember auth correctly.
I'm also considering using read/write hooks on Firestore instead of the API in the future, which might fix that issue as well.
Update: I've removed getting the data from the API, which means it's less reliable on it. But I have to move the new user/character creation back to the client if I want to completely enable offline persistence (assuming it even works).