-
Notifications
You must be signed in to change notification settings - Fork 927
Firebase on React Native should import AsyncStorage from @react-native-community/async-storage #1847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the heads-up. It looks like there's a couple of issues with upgrading right now. First, it seems like Expo users currently can't import native packages without ejecting (react-native-async-storage/async-storage#72). Secondly, we would like a graceful fallback if people are using an older version of React Native, but you can't detect React Native version at runtime. I tried to try/catch We could also explicitly include A good time to do this might be when Expo comes up with a way to allow usage of the new AsyncStorage, and when Firebase has a major version change, which allows us to introduce breaking changes so we don't need to provide a fallback. |
Seems that this is actually bigger problem than it seemed: if It seems to be some sort of race condition. When login happens, @hsubox76 suggestion: what if AsyncStorage could be passed as an additional option when initializing Firebase, or perhaps calling |
I found the problem when using deprecated |
any updates on this? |
Our team is looking to rewrite away from Firebase due to this bug. Injecting AsyncStorage into Firebase as suggested by @hsubox76 seems like it could work for React Native. By default Firebase could use a default storage mechanism, then accept other implementations through a It seems like Firebase would then need to create an abstraction internally to use provided storage mechanisms. I don't know enough about this library to know if that's right, would need to hear from the regular contributors to this project. |
@jsayol made a https://gist.github.com/jsayol/31fb8f488c6ccc6d9ea9aceff995581d |
We are still looking into this issue, which is very tricky because of Expo support. The potential solution you mentioned doesn't address the uncatchable Also you might already be aware, but if not (and for anyone else who is not), there is an official react-native-firebase package especially for using Firebase with React Native that uses the native mobile SDKs, which (1) shouldn't have this specific issue with AsyncStorage and (2) also has some features the JS SDK doesn't. Switching over would probably be somewhat of a time investment but if you were already considering a rewrite away from Firebase this might be less work than that. I realize it's not an option for some people (such as Expo users) and we are actively trying to figure out what to do to resolve this issue for RN and the JS SDK. Our plan so far is to introduce this as a breaking change with the next major version. I don't really have the authority to give a timeline for major version releases but if we stick to a similar schedule as the past it should be in a few months. |
@hsubox76 I didn't know about that library, it looks more than suitable - thank you! |
@hsubox76 Follow up, took about 8 hours to migrate to react-native-firebase, thanks again |
Any news on this issue? A way to resolve this issue for RN and the JS SDK? or allow firebase to use @react-native-async-storage/async-storage Or maybe a date for the breaking change with the next major version is scheduled to be release? @hsubox76 |
@alexdanieldm Been a while since my heads been here, but IIRC the solution for RN is to migrate from this library (which is intended for web environments) to react-native-firebase |
This will be available for v9, which is in beta ( In v9 it will import the (deprecated) AsyncStorage bundled react-native by default (
|
Hi @hsubox76, i want reach out to have confirmation on this
being NOW THE OFFICIAL SOLUTION of Firebase on React Native for the AsyncStorage warnings |
Thanks for bringing this up and sorry for the late reply. Yes, this is intended to be the official solution. We haven't yet exposed |
@hsubox76 - using |
Hi, is there any timeline with regards to getting |
Same problem here. |
Is there any timeline on exposing getReactNativePersistance or just using @react-native-async-storage/async-storage? |
Why go for such a convoluted solution when Expo now fully supports @react-native-async-storage/async-storage?
This requires ejecting on expo which is the exact reason that this issue exists in the first place |
Hey now that v9 is released, is this issue fixed? |
getReactNativePersistence is not exposed, therefore not fixed yet. |
Hi, I'm currently working on an app in expo and I am getting this warning. I am not importing
config file:
|
@Rithu-664 There is more info above, but see the below quotes for a tldr Even if you don't use AsyncStorage anywhere, firebase uses it for auth state persistence (keeping you signed in between sessions). There as some intermediate solutions until AsyncStorage is no longer in React Native and firebase removes it's import (I would hazard a guess at SDK 10 since it's a major breaking change). There is a lot of discussion about why this is needed towards the top of this issue. How to stop your app from breaking if AsyncStorage is removed from RN:
Clarification of behavior:
To hide the warning (after doing the above):
|
I cannot get React Native running on my machine after trying for the better part of a day, so if anyone wants to help test out the fix in #5739 that would be great. To help test it out:
Edit: I did finally manage to get a react-native app working so I'll try to test these things out. |
Hi @hsubox76 |
Just tried it myself, replacing the EDIT: that is to say that @hsubox76 's change completely removes any AsyncStorage warnings for me in both cases and React Native Debugger confirms that it is still using AsyncStorage correctly |
Thanks a lot! The fix is merged and there is a staging release with it if anyone wants to try: |
Just updated to 9.6.5 and it seems like that has properly fixed it; are we ready to close this issue, or wait for more widespread testing? |
i am still getting the same error after update |
Are you passing a persistence layer to initializeAuth? If not, scroll up in the thread a bit (I posted a big TL;DR) |
I followed v9 docs : |
V9 docs are out of date in this case. Scroll up for instructions on how to give firebase the up to date AsyncStorage. |
Followed these instructions and warning went away. thanks!! |
Using firebase 9.6.6, but still seeing asyncstorage error. Sounds like the solution is to use The new async storage should be the default when calling |
Read the discussion above. That would break everyone using the old AsyncStorage. Maybe in v10 but that is a majorly breaking, and nonessential change. |
Hi, I am using firebase 9.6.5 and expo and am attempting to just replace the getAuth() function with the |
Check that you are only using inializeAuth() once and getAuth() after that for getting an auth reference (or the return value of initializeAuth). If you can, maybe add a breakpoint on the line where you call inializeAuth, or if all else fails inside the inializeAuth function itself |
Yeah I was misusing the initializeAuth, I moved it just after the initializeApp() in my seperate firebase script and kept getAuth() as they were in the rest of the program. Thanks for the help! |
Thanks! After replacing getAuth with initializeApp, I got import { initializeApp, FirebaseApp, getApps, getApp } from 'firebase/app';
import { Auth, getAuth, initializeAuth } from 'firebase/auth';
import { getReactNativePersistence } from 'firebase/auth/react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import config from './config.json';
let firebaseApp: FirebaseApp;
let fireAuth: Auth;
if (getApps().length < 1) {
firebaseApp = initializeApp(config);
fireAuth = initializeAuth(firebaseApp, {
persistence: getReactNativePersistence(AsyncStorage),
});
} else {
firebaseApp = getApp();
fireAuth = getAuth();
} |
I replaced my getAuth with initializeAuth. As seen below. Im still getting the warning with no actual error though. Im writing in javascript, so I can't use typescript if that is crucial. Am I missing something? const firebaseApp = initializeApp(config); |
How are you importing |
Im importing it from '@react-native-async-storage/async-storage'; My entire firebase.js file is below. (Reposted as I put my api key in by accident) import {initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ export const firestore = getFirestore(firebaseApp) export const auth = initializeAuth(firebaseApp, { |
I would suggest importing the old async storage and then logging AsyncStorage.getAllKeys() to make sure it's firebase that is still using the old async storage. |
When I use the current AsyncStorage the one I posted above I get this in my console.log
|
Sorry I didn't reply to this at the time but you're importing the firebase auth bundle twice:
You want to do:
|
Describe your environment
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 fromreact-native
and moved into its own packagereact-native-async-storage
.Steps to reproduce:
Add Firebase to React Native app and observe how at the startup there's a warning:
[warn][tid:com.facebook.react.JavaScript] Warning: Async Storage has been extracted from react-native core and will be removed in a future release. It can now be installed and imported from '@react-native-community/async-storage' instead of 'react-native'. See https://github.com/react-native-community/react-native-async-storage
Relevant Code:
firebase-js-sdk/packages/app/index.rn.ts
Line 27 in 96ab56b
The text was updated successfully, but these errors were encountered: