Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting deprecation warning using firebase in react native

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.

like image 482
Muskan Verma Avatar asked Dec 01 '25 18:12

Muskan Verma


1 Answers

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

like image 194
Denis Avatar answered Dec 05 '25 10:12

Denis



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!