Firebase on React Native should import AsyncStorage from @react-native-community/async-storage
Problem
Describe your environment Operating System version: React Native 0.59 Browser version: iOS, Android Firebase SDK version: 6.1.0 Firebase Product: auth Describe the problem When using Firebase on React Native, it uses AsyncStorage from `react-native` under the hood to store the authentication session across app restarts. Starting from RN0.59 AsyncStorage is deprecated from `react-native` and moved into its own package `react-native-async-storage`. Steps to reproduce: Add Firebase to React Native app and observe how at the startup there's a warning: [code block] Relevant Code: https://github.com/firebase/firebase-js-sdk/blob/96ab56bac05ccaf506ed3a02ccad5ff7e01a07d0/packages/app/index.rn.ts#L27
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Update Firebase to Use AsyncStorage from @react-native-async-storage/async-storage
Starting from React Native version 0.59, AsyncStorage has been deprecated from the 'react-native' package and moved to a separate package '@react-native-async-storage/async-storage'. The Firebase SDK version 6.1.0 still references the deprecated AsyncStorage, leading to warnings during app startup.
Awaiting Verification
Be the first to verify this fix
- 1
Install @react-native-async-storage/async-storage
To resolve the warning, you need to install the new AsyncStorage package that is compatible with React Native 0.59 and above.
bashnpm install @react-native-async-storage/async-storage - 2
Link the AsyncStorage package
If you are using React Native version below 0.60, you will need to link the package manually. For React Native 0.60 and above, auto-linking should handle this.
bashreact-native link @react-native-async-storage/async-storage - 3
Modify Firebase SDK to use new AsyncStorage
You may need to modify the Firebase SDK code or create a custom wrapper to ensure it uses the new AsyncStorage package instead of the deprecated one. This involves replacing imports in your project.
javascriptimport AsyncStorage from '@react-native-async-storage/async-storage'; - 4
Test the application
Run your application on both iOS and Android platforms to ensure that the warning is resolved and that authentication works as expected.
bashreact-native run-ios && react-native run-android
Validation
Confirm that the application starts without any warnings related to AsyncStorage. Additionally, verify that the Firebase authentication functionality works correctly by logging in and out.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep