Skip to content

getReactNativePersistence imports AsyncStorage from react-native core (instead of extracted package) causing warning #6493

Closed
@davidhartsough

Description

@davidhartsough

Describe your environment

  • Operating System version: MacOS
  • Browser version: Chrome
  • Firebase SDK version: 9.9.1
  • Firebase Product: auth

Describe the problem

Steps to reproduce:

Add firebase (^9.9.0 or pretty much any version in the past ~year) to a react-native Expo-managed project.

Use any of the auth exported functions, such as:

import {
  getAuth,
  createUserWithEmailAndPassword,
  onAuthStateChanged,
  signInWithEmailAndPassword,
  sendPasswordResetEmail,
  signOut,
  deleteUser,
  User,
  Unsubscribe,
  GoogleAuthProvider,
  signInWithRedirect,
  getRedirectResult,
  FacebookAuthProvider,
  TwitterAuthProvider,
  signInWithCredential,
} from "firebase/auth";

Run the react-native app, say in an Android emulator, using expo.

You'll get the following warning in your console:

AsyncStorage 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-async-storage/async-storage' instead of 'react-native'. See https://github.com/react-native-async-storage/async-storage
at node_modules/react-native/Libraries/Utilities/warnOnce.js:27:2 in warnOnce
at node_modules/react-native/index.js:262:12 in module.exports.get__AsyncStorage
at node_modules/@firebase/auth/dist/rn/index.js:164:43 in getReactNativePersistence$argument_0.setItem
at node_modules/@firebase/auth/dist/rn/index.js:77:53 in tslib.__generator$argument_1

So, because AsyncStorage has moved to @react-native-async-storage/async-storage and extracted from react-native core, we need change the imports in packages/auth/index.rn.ts:

import * as ReactNative from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';

And then the getReactNativePersistence needs to use AsyncStorage instead of react-native core:

export const reactNativeLocalPersistence: Persistence =
  getReactNativePersistence({
    getItem(...args) {
      // Called inline to avoid deprecation warnings on startup.
      return AsyncStorage.getItem(...args);
    },
    setItem(...args) {
      // Called inline to avoid deprecation warnings on startup.
      return AsyncStorage.setItem(...args);
    },
    removeItem(...args) {
      // Called inline to avoid deprecation warnings on startup.
      return AsyncStorage.removeItem(...args);
    },
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions