Getting error when firebase SignOut on react native

Viewed 68

All works ok, sign in, signup, even the database, but when I am trying to sign out this error show up:

[TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[0], "@firebase/util").getModularInstance(auth).signOut')]

This is my firebase file:

import { initializeApp, getApps} from 'firebase/app';
import {initializeAuth, getAuth} from 'firebase/auth';
import { initializeFirestore } from 'firebase/firestore';
import { getReactNativePersistence } from 'firebase/auth/react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {REACT_APP_APIKEY, 
    REACT_APP_AUTHDOMAIN,
    REACT_APP_PROJECTID,
    REACT_APP_STORAGEBUCKET,
    REACT_APP_MESSAGINGSENDERID,
    REACT_APP_APPID

} from "@env"
// Firebase config
const firebaseConfig = {
  apiKey: REACT_APP_APIKEY,
  authDomain: REACT_APP_AUTHDOMAIN,
  projectId: REACT_APP_PROJECTID,
  storageBucket: REACT_APP_STORAGEBUCKET,
  messagingSenderId: REACT_APP_MESSAGINGSENDERID,
  appId: REACT_APP_APPID,
  
};
// initialize firebase

let firebaseApp;
let auth;

if (getApps().length < 1) {
   firebaseApp = initializeApp(firebaseConfig);
   auth = initializeAuth(firebaseApp, {
    persistence: getReactNativePersistence(AsyncStorage),
});
}  else {
    auth = getAuth();
}

export default auth;
export const database = initializeFirestore(firebaseApp, {
    experimentalForceLongPolling: true,
  });

This is when I am calling the function:

import { signOut } from 'firebase/auth';
 import {database, auth} from '../config/firebase';

  const onSignOut = () => {
    try {
      signOut(auth).then(()=> console.log("signout"))
    } catch (error) {
      console.log('Error logging out: ', error)
    }
  };
1 Answers

I finally found the problem, it was my mistake.

As you can see in my firebase file, I export the "auth" as default, but when I am trying to import it, I am importing inside the curly braces {auth}, but It must be outside due it is default. I fixed that and the problem is fixed.

this is the right way:

import auth, {database} from '../config/firebase';
Related