Use ReactNativeAsyncStorage from community package. by hsubox76 · Pull Request #7128 · firebase/firebase-js-sdk (original) (raw)
Why
When updating an example using the Firebase JS SDK, I found out that it
wasn't persisting the auth session, meaning you had to login again every
time you refreshed. At some point after firebase 9.1.3, it started
defaulting to in-memory storage**. Between all the pre-9.x instructions
still out there and the tendency for internet searches to return
instructions that work for web but not React Native, but without saying
they don't work for React Native, it's tricky to find what you need.
Further, once you find the needed reactNativeLocalPersistence
persistence provider, you'll find that it doesn't work in SDK 48, as it
uses the now-removed core local storage. This at least will be fixed
soon. While the
custom persistence code should be short-lived, at least overriding the
default persistence could be necessary indefinitely. It took me several
hours to figure this all out, the Firebase JS SDK can otherwise be a
splendid way to quickly bootstrap an app, so would like to save others
the trouble with a concise, complete, and confirmed-working code
example.
** EDIT: as I read me, it seems possible that this is instead fallback
behavior due to local persistence not working, so don't want to presume
it's an intentional default. Depending on how I apply
reactNativeLocalPersistence, I can get actual errors about missing
local storage functionality, or it fails silently, and the silent
failure scenario is the exact same code that used to give me a
deprecation warning, so it's unclear.
How
Created an FYI with the details, added a callout for additional auth configuration in the Using Firebase guide.
Test Plan
Looked at the doc, tried the link.
Checklist
- Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md).