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?
Firebase Realtime Database security rules are always evaluated on the server side. This prevents malicious clients from bypassing those rules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With