3

I am using firebase in my react native project for authentication and getting this warning even after updating my code according to modular api -

This method is deprecated (as well as all React Native Firebase namespaced API) and will be removed in the next major release as part of move to match Firebase Web modular SDK API. Please see migration guide for more details: https://rnfirebase.io/migrating-to-v22 Please use where() instead.

This is my code where the warning occurs -

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;
        }
    };

I have checked the instruction mentioned in new documentation but still getting the warning.

3
  • 1
    Which line of the lines you've shown generates that error? It seems to me that none of the lines shown here are using the deprecated API. Please edit the question to be clear. Commented Feb 14 at 19:43
  • I have already changed the code according to modular api but it is still showing the deprecation error. That's why I am asking what is wrong here. And the deprecation is in this part for sure because when I am commenting this lines it is not showing deprecation error. @DougStevenson Commented Feb 16 at 1:15
  • add this line at App.js globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; Commented Aug 6 at 12:22

4 Answers 4

3

This is how to solve the issue on the messaging module example.

  1. Use this type of the import:
import { getMessaging, requestPermission, setBackgroundMessageHandler, onMessage, getToken, onNotificationOpenedApp, getInitialNotification, subscribeToTopic, hasPermission } from '@react-native-firebase/messaging';
  1. Remove all messaging() calls and use imported methods directly. All of them (except getMessaging) require first additional argument: messaging instance.

Old code:

messaging().getInitialNotification().then(message => this.catchMessage(message));
var token = await messaging().getToken();

New code:

const messagingInstance = getMessaging();

getInitialNotification(messagingInstance).then(message => this.catchMessage(message));
var token = await getToken(messagingInstance);

Big example code is given here: https://github.com/invertase/react-native-firebase/issues/8282#issuecomment-2760400136

Sign up to request clarification or add additional context in comments.

Comments

0

Correct Import for Firestore (Modular API)

Instead of:

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

Use:

import { getFirestore, collection, query, where, getDocs } from "firebase/firestore";

If you have this anywhere in your project, remove it and switch to the modular API.

Check Your Firebase Initialization:

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;

Update all dependencies:

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

Summary:

  1. Remove any old namespaced imports
  2. Use modular API imports
  3. Ensure you're using getFirestore(app) in your Firebase setup
  4. Update Firebase SDK versions and clear Metro cache

1 Comment

Did all this already but it is still showing deprecation error.
0

It should be

import { collection, query, where, getDocs, getFirestore } from '@react-native-firebase/firestore'

Checkout the docs: https://rnfirebase.io/migrating-to-v22

Comments

0

I was getting the following warning when using Firebase Authentication in my React Native project, even after updating my code to follow the modular API:

This method is deprecated (as well as all React Native Firebase namespaced API) and will be removed in the next major release as part of move to match Firebase Web modular SDK API. Please see migration guide for more details: https://rnfirebase.io/migrating-to-v22

After checking the migration guide and trying several things, I finally resolved it by replacing:

import auth from '@react-native-firebase/auth';

with:

import { getAuth } from '@react-native-firebase/auth';
import { getApp } from '@react-native-firebase/app';

const app = getApp();
const auth = getAuth(app);

By doing this, the warning disappeared.

So if you're seeing this warning even when using modular Firestore code, double-check that none of your other Firebase imports (like auth) are still using the old namespaced syntax. That was the issue in my case.

Hope this helps someone else!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.