How to disable offline persistence with react-redux-firebase

379 Views Asked by At

I have a web application with React, Redux that connects to the Firebase's Realtime Database. Implementation uses react-redux-firebase library and it works.

Out of the box, if the app goes temporarily offline, changes to store are saved locally and are then executed once online again. The feature is called "offline persistence" by Firebase. I want to turn this off - if the application is offline, no actions should work and later, when internet is reconnected, no changes should be pushed to server.

How can I do this? I can't find it in react-redux-firebase's documentation or configuration. Neither switching from Realtime Database to Firestore changes this. As a side problem, the app writes errors to the console while offline. Everything works, but once again, I don't know how to turn these logs off.

WebSocketConnection.ts:183 WebSocket connection to 'wss...' failed: Error in connection establishment: net::ERR_INTERNET_DISCONNECTED
WebSocketConnection.open @ WebSocketConnection.ts:183
(anonymous) @ Connection.ts:145
BrowserPollConnection.ts:745 GET https://... net::ERR_INTERNET_DISCONNECTED
1

There are 1 best solutions below

2
On

You can detect whether the Firebase client is connected to the server by listening for the .info/connected node. When this is the case, you can prevent your code from sending any write operations to the database.

For an example of this, see the Firebase documentation on detecting connection state.