Abdul-Qader Haddad
Abdul-Qader Haddad

Reputation: 57

(firebase.firestore is not a function) when trying to create collection in Firestore

So I've been learning RN w/ Firebase using Expo, and I'm following this guide:
https://medium.com/swlh/expo-firebase-authentication-cloud-firestore-using-async-await-react-hooks-700920ad4b2b

I'm using snack.expo, here's a link to whole project: https://snack.expo.io/@abdulqader98/project_firebaseauth

However, in the app whenever I "Sign Up" for a new account I get this error:
"firebase.firestore is not a function. (In 'firebase.firestore()'. 'firebase.firestore' is undefined)"

Firebase Auth works properly, the Email and Password are saved and I can Log in, but none of the user info is saved into Firestore. I've researched this problem for hours, but no bueno.
Any help is greatly appreciated.

Code snippets:
keys.js:

export default {
 firebaseConfig: {
    apiKey: "AIzaSyDubiJeKCLUUUtzOGGC-sXpZi8t2WgIXIQ",
    authDomain: "car-wash-project-59e08.firebaseapp.com",
    projectId: "car-wash-project-59e08",
    storageBucket: "car-wash-project-59e08.appspot.com",
    messagingSenderId: "849352959520",
    appId: "1:849352959520:web:e5fa4f5ed2d56d24cebe45"
    }
}

firebaseMethods.js (I think the problem is somewhere around here)

import * as firebase from 'firebase';
import 'firebase/firestore';
import {Alert} from 'react-native';

export async function registration(email, password, lastName, firstName) {
  try {

    await firebase.auth().createUserWithEmailAndPassword(email, password);
    const currentUser = firebase.auth().currentUser;

    const db = firebase.firestore();
    db.collection('users')
      .doc(currentUser.uid)
      .set({
        email: currentUser.email,
        lastName: lastName,
        firstName: firstName,
      });
  } catch (err) {
    Alert.alert('There is something wrong! #1', err.message);
  }
}

export async function signIn(email, password) {
  try {
    await firebase
      .auth()
      .signInWithEmailAndPassword(email, password);
  } catch (err) {
    Alert.alert('There is something wrong! #2', err.message);
  }
}

export async function loggingOut() {
  try {
    await firebase.auth().signOut();
  } catch (err) {
    Alert.alert('There is something wrong! #3', err.message);
  }
}

Upvotes: 0

Views: 286

Answers (1)

Javier A
Javier A

Reputation: 569

You should set up a local development environment with expo cli: docs.expo.io/get-started/installation. Sometimes libraries don't work quite as well in snack due to some limitations of the environment.

Upvotes: 1

Related Questions