Firebase offline only if user opts out

1,173 views
Skip to first unread message

Martin Hollerweger

unread,
Mar 19, 2016, 12:46:46 PM3/19/16
to Firebase Google Group
My App should support authentication and database synchronization but should also work fully offline if the user doesn't like to synchronize his data.
  • Is the first start of the App with Firebase even possible offline?
  • Is it possible to use Firebase as a offline only database if the user doesn't want to synchronize his data?
  • Can I write to Firebase before the user authenticates?
    • If the user later authenticates. Can I sill synchronize the offline data with the firebase backend where authentication is required?
Thanks in advance for any constructive answer

Best,
Martin

Kasey Moffat

unread,
Mar 21, 2016, 10:27:47 AM3/21/16
to Firebase Google Group
+1, would be great to know the answer to this question!  Asked a similar question here: https://groups.google.com/forum/#!topic/firebase-talk/kXdVJNYMpMU

Jonny Dimond

unread,
Mar 21, 2016, 7:43:58 PM3/21/16
to Firebase Google Group
Hey Martin & Kasey,

Two answer some of the questions:
  • The first start does work offline in principle, however, the client will not raise events for paths it has not seen previously while offline, so it probably is not recommended in practice.
  • The current offline mode is not recommended for indefinite offline use, it will eventually run into performance issues.
  • Whenever Firebase comes online it will attempt to synchronize data with the current authentication token, if you are unauthenticated it will synchronize the data unauthenticated.
Jonny

Kasey Moffat

unread,
Mar 21, 2016, 10:54:16 PM3/21/16
to Firebase Google Group
Thanks for the response Jonny!  Regarding bullet 3, can I request a way to ensure the client only attempts to write offline data to the server after authentication is successful?  I'm trying to handle the following situation:

1) The first start is offline.  I use setValue to initially create user data then updateChildValues on children so the client continues to raise events while offline.
2) The client eventually comes online.
3) The client attempts to write offline events to the server.

What I would like is a way to ensure authentication happens before 3), otherwise security rules may prevent writes from completing and data is lost.  With the current state of things, if the user is offline on first start I have to notify them they need to be online before using the app the first time.

For context, this is for a game where the user doesn't need to authenticate to start playing (I'm using anonymous auth), but can choose to login later to unlock additional features.  It's the same login/connection model Candy Crush uses (which I've verified works offline/anonymously on first start).

The Firebase Offline Capabilities docs say offline writes are paused if the auth token expires - maybe there could be a setting to pause writes before any authentication at all?

"If your app uses Firebase Authentication, the client will persist the user's authentication token across restarts. If the auth token expires while our app is offline, the client will pause our write operations until we re-authenticate, else our writes might fail due to security rules."

Kato Richardson

unread,
Mar 22, 2016, 10:30:12 AM3/22/16
to Firebase Google Group
Hi Casey,

This doesn't sound like a feature we'll be adding soon. Your best approach would be to store in a temporary location, perhaps using an anonymous auth id, until your users unlock/register and then to move it to their permanent location then. 

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/486abf93-007d-40ad-9950-da903c57c69a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Kasey Moffat

unread,
Mar 22, 2016, 4:32:32 PM3/22/16
to Firebase Google Group
Hi Kato,

Unless I'm misunderstanding, that workaround requires the client be online and authenticated (anonymous or otherwise) before any writes to the server are attempted.

I'm asking to support the case where the client is offline on first start.  In this case, the client will queue writes until a connection is reestablished.  When a connection is reestablished, I haven't found a way to ensure the client authenticates (anonymous or otherwise) before the offline writes are attempted.  I've tried listening on .info/connected and authenticating as soon as a connection is reestablished, but in my tests the queued offline writes are attempted before authentication completes, and if you have a simple "auth != null" security rule the write fails and data is lost.  I'm happy to send a minimal example if that helps.

I suppose I could write to a temporary location without the "auth != null" security rule, but that would be completely unsecured.

In any case, the Firebase client already pauses writes if the stored auth token is expired, so I would be asking for something like a setting to pause writes if there's no auth token at all.

Sorry if I'm missing something, I'm still learning all the ins and outs of Firebase but loving it so far!

Kasey

Martin Hollerweger

unread,
Mar 24, 2016, 9:48:16 AM3/24/16
to Firebase Google Group
Hi Kasey,

I also would need to halt the synchronization until the user authenticates.

The only why I think it would work now is to have a separate Database until the user authenticates and than copy the data over to firebase.

Best Martin

Mi Ni

unread,
May 31, 2016, 5:16:42 PM5/31/16
to Firebase Google Group
i think its a good workflow if the user can test the application offline - but if he like sync on other devices or connect with other users he can sign up to go to the cloud

until now there is only the possibility to code the db twice: one for local and later for online

it would be nice if there is a completed offline mode -> all user data is stored local and if user like to go to the cloud then all data should be transfered to the cloud with one step after he sign up.
Reply all
Reply to author
Forward
0 new messages