Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find getReactNativePersistence when using Firebase Auth with AsyncStorage in React Native (Expo)

I'm developing a React Native app using Expo and trying to persist Firebase Auth state across sessions with AsyncStorage.

Here is my firebaseConfig.ts file:

import { initializeApp } from "firebase/app";
import { initializeAuth, getReactNativePersistence } from "firebase/auth";
import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';

const firebaseConfig = {
  apiKey: "...",
  authDomain: "...",
  projectId: "...",
  storageBucket: "...",
  messagingSenderId: "...",
  appId: "..."
};

export const app = initializeApp(firebaseConfig);
export const auth = initializeAuth(app, {
  persistence: getReactNativePersistence(ReactNativeAsyncStorage) 
});

When trying to import getReactNativePersistence, I get this error:

Module '"firebase/auth"' has no exported member 'getReactNativePersistence'.

Is there any way to properly use getReactNativePersistence in this setup, or another recommended approach to persist Firebase Auth state in Expo without ejecting or using a custom dev client?

Any help would be appreciated!

What I've already tried:

Installed dependencies:

npm install firebase
npm install @react-native-async-storage/async-storage

My package.json includes:

"@react-native-async-storage/async-storage": "^2.1.2",
"firebase": "^11.8.1"

Tried adding this to tsconfig.json based on suggestions I found:

{
  "compilerOptions": {
    "paths": {
      "@firebase/auth": ["./node_modules/@firebase/auth/dist/index.rn.d.ts"]
    }
  },
  "extends": "expo/tsconfig.base"
}

However, this did not solve the issue. Also, when I check my node_modules/@firebase directory, there is no auth folder at all.

like image 462
Sabatini Avatar asked Aug 07 '26 17:08

Sabatini


1 Answers

Expo SDK 53 and above requires you to use firebase version 12 (as specified here). Try re-installing it with this version to solve the auth folder issue.

For the error, according to the release notes, there was an entry point added in version 11.10. However, it appears that with version 12, this entry point as been silently removed. The firebase node module doesn't have a React Native file or folder anymore (firebase/auth/dist/rn or firebase/auth/dist/index.rn.d.ts).

The only solution I have found after scouring GitHub is to ignore the error with //@ts-ignore. Strangely, the persistent logic appears to work, and the app will run just fine so it's possible that this function is hidden somewhere.

like image 193
Siddharth Panjwani Avatar answered Aug 09 '26 08:08

Siddharth Panjwani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!