react-native-firebase
react-native-firebase copied to clipboard
[🐛] Firestore get document doesn't work in production
Issue
I recently migrated my expo app to use react-native-firebase instead of bare firebase module. But when i pushed the changes to production, the react-native-firebase/firestore module return an null every time . I kept some functions that still use firebase/firestore modules and they still work (for documents that don't need auth permissions). bellow is the code i'm using to test the scenerios:
code i'm using to test
useEffect(() => {
// works in production
async function test() {
try {
const userRef = doc(db, "users", "user-id");
const userSnap = await getDoc(userRef);
Alert.alert("user snap", JSON.stringify(userSnap.data()));
} catch (err) {
Alert.alert("error getting user", JSON.stringify(err));
}
}
test();
async function test2() {
try {
// fails in production
const userRef = firestore().collection("users").doc("user-id");
const userSnap = await userRef.get();
Alert.alert("user snap", JSON.stringify(userSnap.data()));
} catch (err) {
Alert.alert("error getting user", JSON.stringify(err));
}
}
test2();
}, []);
The problem is only happening in production and i don't have good loging setup currently. I'd really appreciate help figuring out what is going wrong.
Project Files
Javascript
Click To Expand
package.json
:
{
"name": "example",
"version": "1.0.0",
"main-old": "node_modules/expo/AppEntry.js",
"main": "expo-router/entry",
"scripts": {
"start": "expo start",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web"
},
"dependencies": {
"@expo-google-fonts/inter": "^0.2.3",
"@expo/webpack-config": "^19.0.0",
"@gorhom/bottom-sheet": "^4.6.0",
"@notifee/react-native": "^7.8.2",
"@react-native-async-storage/async-storage": "^1.19.5",
"@react-native-firebase/analytics": "^20.0.0",
"@react-native-firebase/app": "^20.0.0",
"@react-native-firebase/auth": "^20.0.0",
"@react-native-firebase/crashlytics": "^20.0.0",
"@react-native-firebase/firestore": "^20.0.0",
"@react-native-firebase/messaging": "^20.0.0",
"@react-native-google-signin/google-signin": "^10.1.2",
"@react-navigation/bottom-tabs": "^6.5.11",
"@react-navigation/drawer": "^6.6.4",
"@react-navigation/material-top-tabs": "^6.6.4",
"@react-navigation/native": "^6.1.9",
"@react-navigation/native-stack": "^6.9.13",
"@react-navigation/stack": "^6.3.20",
"expo": "~49.0.8",
"expo-background-fetch": "~11.3.0",
"expo-build-properties": "~0.8.3",
"expo-clipboard": "~4.3.1",
"expo-constants": "~14.4.2",
"expo-crypto": "~12.4.1",
"expo-font": "~11.4.0",
"expo-haptics": "~12.4.0",
"expo-image": "~1.3.5",
"expo-linking": "~5.0.2",
"expo-notifications": "~0.20.1",
"expo-router": "^2.0.3",
"expo-splash-screen": "~0.20.5",
"expo-status-bar": "~1.6.0",
"expo-task-manager": "~11.3.0",
"expo-updates": "~0.18.19",
"firebase": "^10.11.1",
"moment": "^2.29.4",
"react": "18.2.0",
"react-native": "0.72.6",
"react-native-confirmation-code-field": "^7.3.2",
"react-native-dotenv": "^3.4.9",
"react-native-gesture-handler": "~2.12.0",
"react-native-markdown-display": "^7.0.2",
"react-native-phone-number-input": "^2.1.0",
"react-native-reanimated": "~3.3.0",
"react-native-safe-area-context": "4.6.3",
"react-native-screens": "~3.22.0",
"react-native-svg": "13.9.0",
"react-native-tab-view": "^3.5.2",
"react-native-ui-lib": "^7.10.0",
"react-native-url-polyfill": "^2.0.0",
"react-native-web": "~0.19.6",
"react-native-webview": "^13.6.2",
"uuid": "^9.0.1",
"victory-native": "^36.8.5",
"zustand": "^4.4.3"
},
"devDependencies": {
"@babel/core": "^7.23.3",
"@types/react": "~18.2.14",
"@types/react-native": "^0.72.2",
"@types/uuid": "^9.0.7",
"typescript": "^5.1.3"
},
"expo": {
"scheme": "example"
}
}
firebase.json
for react-native-firebase v6:
# N/A
iOS
Click To Expand
ios/Podfile
:
- [ ] I'm not using Pods
- [x] I'm using Pods and my Podfile looks like:
require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking")
require File.join(File.dirname(`node --print "require.resolve('react-native/package.json')"`), "scripts/react_native_pods")
require 'json'
podfile_properties = JSON.parse(File.read(File.join(__dir__, 'Podfile.properties.json'))) rescue {}
ENV['RCT_NEW_ARCH_ENABLED'] = podfile_properties['newArchEnabled'] == 'true' ? '1' : '0'
ENV['EX_DEV_CLIENT_NETWORK_INSPECTOR'] = podfile_properties['EX_DEV_CLIENT_NETWORK_INSPECTOR']
platform :ios, podfile_properties['ios.deploymentTarget'] || '13.0'
install! 'cocoapods',
:deterministic_uuids => false
prepare_react_native_project!
# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...), which will be excluded. To fix this,
# you can also exclude `react-native-flipper` in `react-native.config.js`
#
# ```js
# module.exports = {
# dependencies: {
# ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# }
# }
# ```
flipper_config = FlipperConfiguration.disabled
if ENV['NO_FLIPPER'] == '1' then
# Explicitly disabled through environment variables
flipper_config = FlipperConfiguration.disabled
elsif podfile_properties.key?('ios.flipper') then
# Configure Flipper in Podfile.properties.json
if podfile_properties['ios.flipper'] == 'true' then
flipper_config = FlipperConfiguration.enabled(["Debug", "Release"])
elsif podfile_properties['ios.flipper'] != 'false' then
flipper_config = FlipperConfiguration.enabled(["Debug", "Release"], { 'Flipper' => podfile_properties['ios.flipper'] })
end
end
target 'ExampleProject' do
use_expo_modules!
config = use_native_modules!
use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']
use_frameworks! :linkage => ENV['USE_FRAMEWORKS'].to_sym if ENV['USE_FRAMEWORKS']
# Flags change depending on the env values.
flags = get_default_flags()
use_react_native!(
:path => config[:reactNativePath],
:hermes_enabled => podfile_properties['expo.jsEngine'] == nil || podfile_properties['expo.jsEngine'] == 'hermes',
:fabric_enabled => flags[:fabric_enabled],
# An absolute path to your application root.
:app_path => "#{Pod::Config.instance.installation_root}/..",
# Note that if you have use_frameworks! enabled, Flipper will not work if enabled
:flipper_configuration => flipper_config
)
post_install do |installer|
react_native_post_install(
installer,
config[:reactNativePath],
:mac_catalyst_enabled => false
)
__apply_Xcode_12_5_M1_post_install_workaround(installer)
# This is necessary for Xcode 14, because it signs resource bundles by default
# when building for devices.
installer.target_installation_results.pod_target_installation_results
.each do |pod_name, target_installation_result|
target_installation_result.resource_bundle_targets.each do |resource_bundle_target|
resource_bundle_target.build_configurations.each do |config|
config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
end
end
end
end
post_integrate do |installer|
begin
expo_patch_react_imports!(installer)
rescue => e
Pod::UI.warn e
end
end
end
AppDelegate.m
:
// N/A
Android
Click To Expand
Have you converted to AndroidX?
- [ ] my application is an AndroidX application?
- [ ] I am using
android/gradle.settings
jetifier=true
for Android compatibility? - [ ] I am using the NPM package
jetifier
for react-native compatibility?
android/build.gradle
:
// N/A
android/app/build.gradle
:
// N/A
android/settings.gradle
:
// N/A
MainApplication.java
:
// N/A
AndroidManifest.xml
:
<!-- N/A -->
Environment
Click To Expand
react-native info
output:
OUTPUT GOES HERE
-
Platform that you're experiencing the issue on:
- [ ] iOS
- [ ] Android
- [x] iOS but have not tested behavior on Android
- [ ] Android but have not tested behavior on iOS
- [ ] Both
-
react-native-firebase
version you're using that has this issue:-
20.0.0
-
-
Firebase
module(s) you're using that has the issue:-
react-native-firebase/firestore v20.0.0
-
-
Are you using
TypeScript
?-
Y
&5.1.3
-
- 👉 Check out
React Native Firebase
andInvertase
on Twitter for updates on the library.