You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo 53+React 19环境下Firebase Auth持久化配置时getReactNativePersistence不存在的问题求助

Expo 53+React 19环境下Firebase Auth持久化配置时getReactNativePersistence不存在的问题求助

最近在启动React Native应用(Android和iOS端均出现问题)时,收到了Firebase Auth的警告提示:

WARN [2025-05-08T11:23:11.890Z] @firebase/auth: Auth (11.6.1): You are initializing Firebase Auth for React Native without providing AsyncStorage. The authentication state will by default persist in memory and will not persist between sessions. To persist the auth state, install the package "@react-native-async-storage/async-storage" and provide it to initializeAuth:

提示里给出的持久化配置示例代码是:

import { initializeAuth, getReactNativePersistence } from 'firebase/auth';
import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage/async-storage';
const auth = initializeAuth(app, { 
  persistence: getReactNativePersistence(ReactNativeAsyncStorage) 
});

但当我按照这个示例实现时,却遇到了TypeScript/JS错误:

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


🛠 我的依赖版本

{
  "@react-native-async-storage/async-storage": "2.1.2",
  "@react-native-firebase/app": "^22.1.0",
  "@react-native-firebase/auth": "^22.1.0",
  "expo": "^53.0.5",
  "react": "19.0.0"
}

📄 当前的Firebase配置文件(src/firebase/index.js)

import { initializeApp } from 'firebase/app';
import { 
  initializeAuth, 
  getReactNativePersistence, // ❌ 错误:找不到该导出成员
  browserLocalPersistence, 
} from 'firebase/auth';
import { Platform } from 'react-native';
import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';
import { getFirestore } from 'firebase/firestore';
import { getStorage } from "firebase/storage";

const firebaseConfig = { 
  // ... 我的Firebase配置信息
};

export const FIREBASE_APP = initializeApp(firebaseConfig);
export const FIREBASE_DB = getFirestore(FIREBASE_APP);
export const FIREBASE_STORAGE = getStorage(FIREBASE_APP);

const auth = initializeAuth(FIREBASE_APP, {
  persistence: ['ios', 'android'].includes(Platform.OS) 
    ? getReactNativePersistence(ReactNativeAsyncStorage) 
    : browserLocalPersistence,
});

export const FIREBASE_AUTH = auth;

之前使用Expo SDK 52时一切正常,但升级到SDK 53后就出现了这个问题,现在完全找不到适配Expo 53和React 19的持久化Auth配置正确方式了。

想请教大家:

  • 现在应该如何正确使用getReactNativePersistence?
  • Firebase Auth 11.x版本在这部分有什么变更吗?
  • 有没有适配Expo 53和React 19的最新配置示例?

提前感谢大家的帮助 🙏

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 12:29:30