Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Database not loading data offline

I have an app that uses Firebase Database in offline mode (by calling FirebaseDatabase.getInstance().setPersistenceEnabled(true)). In the database there is a node that user can access only if value in other node is set to true, the rules look like this:

{
  "rules": {
    ".write": "auth != null",
    ".read": "false",
    "mynode": {
      "$dataId": {
        ".read": "auth != null && root.child('userAccessNode/' + auth.uid + '/' + $dataId).val() == true"
      }
    }
  }
}

It works correctly when device is connected to internet. However when I turn flight mode on the device the callback addValueEventListener(ValueEventListener) doesn't return anything - nor error, not value, just hangs until I turn on internet connection again.

I made sure that both nodes were retrieved before going offline, so I was sure the node in question and node holding access information was cached.

For other nodes that have simple rules like (auth != null) offline mode works fine, but not in this case.

Am I doing anything wrong? Any idea how can I make this work? How does rules (that depend on other nodes) evaluation work when offline?

like image 992
Marcin Bak Avatar asked Oct 30 '22 10:10

Marcin Bak


1 Answers

Firebase Realtime Database security rules are always evaluated on the server side. This prevents malicious clients from bypassing those rules.

like image 192
Doug Stevenson Avatar answered Nov 15 '22 05:11

Doug Stevenson