[🐛] RTDB listener provides stale cached data before firing permission denied error; cache not invalidated #8475
Labels
blocked: customer-response
platform: ios
plugin: database
Firebase Realtime Database
type: bug
New bug report
Issue 🔥
RTDB listener provides stale cached data offline without error, even after receiving permission denied online
When listening to a Firebase Realtime Database path using
@react-native-firebase/database
with offline persistence enabled, if security rules initially allow access but are later changed to deny access, the SDK fails to consistently report the permission denial when the app is subsequently launched offline, leading to stale data being presented as valid.Expected Behavior:
database/permission-denied
error.a. Not deliver any
value
event from the cache for that path, ORb. Deliver the
value
event and immediately deliver adatabase/permission-denied
error again (based on its knowledge that permission was revoked).Observed Behavior:
/users/{userId}/someData
) with offline persistence enabled (firebase.database().setPersistenceEnabled(true)
).canReadData = true
). Data is received correctly via thevalue
callback and stored in the offline cache.canReadData
becomesfalse
). This happens while the app is online.a. The listener's
value
callback often fires first, providing the last known stale data from the offline cache.b. Subsequently, the listener's
error
callback is invoked with the correct[database/permission-denied]
error. The application and SDK now know access is denied for this path.c. Application-level workarounds (detaching listener, clearing state in the error handler) can mitigate UI display issues in this online scenario.
a. Following the steps above, the app knows permission for
/users/{userId}/someData
is denied.b. The user takes the app offline (disables WiFi/cellular).
c. The user relaunches the app while still offline.
d. The listener for
/users/{userId}/someData
is re-attached (e.g., in auseEffect
hook).e. The listener's
value
callback fires, providing the stale data from the offline cache.f. Crucially, the
error
callback with[database/permission-denied]
is NEVER received in this offline relaunch scenario, despite the SDK having previously received this specific error for this specific path while online.g. The SDK fails to retain or re-apply the known "permission denied" state for the path when operating offline. As a result, the application treats the stale cached data as valid, potentially rendering it, and any error-handling workarounds are never triggered because the necessary error event is missing.
database/permission-denied
error is received online.Code Snippet (Illustrating Workaround - Ineffective Offline):
Summary of Problem: The core issue is now threefold:
value
listener before signaling thedatabase/permission-denied
error.database/permission-denied
error online for a specific path, if the app is relaunched offline, the SDK delivers stale cached data for that path via thevalue
listener but fails to deliver the correspondingdatabase/permission-denied
error again. It effectively "forgets" the known permission state when offline.The application-level workaround (clearing state/detaching listener in the error handler) is completely ineffective for the critical offline relaunch case because the SDK fails to re-signal the previously known error state. This presents a significant data integrity risk for offline-capable apps relying on RTDB permissions.
Project Files
Javascript
Click To Expand
package.json
:firebase.json
for react-native-firebase v6:# N/A (Add if you have customizations)
iOS
Click To Expand
ios/Podfile
:AppDelegate.m
/AppDelegate.mm
:// N/A (Add if relevant modifications were made, e.g., Firebase initialization)
Android
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility? (Select if correct)jetifier
for react-native compatibility? (Select if correct)android/build.gradle
:// N/A (Add if relevant modifications were made, e.g., Firebase classpath)
android/app/build.gradle
:// N/A (Add if relevant modifications were made, e.g., Firebase plugin, dependencies)
android/settings.gradle
:// N/A (Add if relevant modifications were made)
MainApplication.java
/MainApplication.kt
:// N/A (Add if relevant modifications were made)
AndroidManifest.xml
:<!-- N/A (Add if relevant modifications were made) -->
Environment
Click To Expand
react-native info
output:react-native-firebase
version you're using that has this issue: 0.77.1@react-native-firebase/app: 21.12.3
,@react-native-firebase/database: 21.12.3
Firebase
module(s) you're using that has the issue:@react-native-firebase/database
TypeScript
?Y
&VERSION 5.0.4
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: