用firebase在react react native中使用firecation警告 我正在我的React Native项目中使用Firebase进行身份验证并获得此警告,即使根据模块化API更新我的代码后, 该方法被弃用(以及所有反应na ...

问题描述 投票:0回答:1
请改用

where()

这是我的代码,警告发生- const checkUsernameUnique = async (userName) => { try { const usersRef = collection(db, 'Users'); const q = query(usersRef, where('username', '==', userName)); const snapshot = await getDocs(q); return snapshot.empty; // ✅ Returns true if no user found } catch (error) { console.error('Error checking username uniqueness:', error); return false; } }; const checkEmailUnique = async (email) => { try { const usersRef = collection(db, 'Users'); const q = query(usersRef, where('email', '==', email)); const snapshot = await getDocs(q); return snapshot.empty; } catch (error) { console.error('Error checking email uniqueness:', error); return false; } };

我已经检查了新文档中提到的指令,但仍会收到警告。
    

Firestore(模块化API)的校正进口 instead:

import firestore from "@react-native-firebase/firestore";

使用:

firebase react-native google-cloud-firestore react-native-firebase
1个回答
0
投票
import { getFirestore, collection, query, where, getDocs } from "firebase/firestore";

如果您在项目中的任何地方都有此功能,请将其删除并切换到模块化API。

检查您的壁炉初始化:

import { initializeApp } from "firebase/app"; import { getFirestore, initializeFirestore } from "firebase/firestore"; const firebaseConfig = { apiKey: "", authDomain: "", projectId: "", storageBucket: "", messagingSenderId: "", appId: "", measurementId: "", }; export const app = initializeApp(firebaseConfig); const db = initializeFirestore(app, { experimentalForceLongPolling: true }); export default db;
auppate所有依赖性:

npm install firebase@latest @react-native-firebase/app @react-native-firebase/firestore summary:


删除任何旧名称步骤导入

使用模块化API进口

确保您在firebase设置中使用getfirestore(app)

Update Firebase SDK版本和清除地铁cache


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.