Home > database >  React Native Expo Firebase Auth not working on Version 9
React Native Expo Firebase Auth not working on Version 9

Time:01-30

I got an error "_config.firebase.auth is not a function. (In '_config.firebase.auth()','_config.firebase.auth' is undefined)

This error appears when submitting a registration form.

I run Firebase version 9.6.5

Can anyone spot where I went wrong in my config.js and RegScreen.js files?

import firebase from 'firebase/compat/app';
import '@firebase/auth';
import '@firebase/firestore';

const firebaseConfig = {
  apiKey: '',
  authDomain: 'to-do-weather.firebaseapp.com',
  databaseURL: 'https://DATABASE_NAME.firebaseio.com',
  projectId: 'to-do-weather',
  storageBucket: 'to-do-weather.appspot.com',
  messagingSenderId: '',
  appId: '',
};

let app;

if (firebase.apps.length === 0) {
  app = firebase.initializeApp(firebaseConfig)
} else {
  app = firebase.app();
}

export { firebase };

    const onRegPress = () => {
        if (password !== confirmPassword) {
            alert("Passwords don't match.")
            return
        }
        firebase
            .auth()
            .createUserWithEmailAndPassword(email, password)
            .then((response) => {
                const uid = response.user.uid
                const data = {
                    id: uid,
                    email,
                    fullName,
                };
                const usersRef = firebase.firestore().collection('users')
                usersRef
                    .doc(uid)
                    .set(data)
                    .then(() => {
                        navigation.navigate('Home', {user: data})
                    })
                    .catch((error) => {
                        alert(error)
                    });
            })
            .catch((error) => {
                alert(error)
        });
    }

CodePudding user response:

If you are trying to use namespaced syntax then you must import compat versions of all Firebase services too. Try changing your imports to:

import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
// add /compat   ^

The compat version would be removed eventually so I would recommend updating your code and following the new syntax as mentioned in the documentation

  •  Tags:  
  • Related