title: Firestore: Could not reach Cloud Firestore backend. Connection failed 1 times
body: <p>I have a <strong>Firebase</strong> real-time database integrated with <strong>React Native</strong> where I can create users. But my problem is that when I try to log in I get an error. I run my app on <strong>IOS</strong> if it makes any difference. I have followed this guide: <a href="https://www.freecodecamp.org/news/react-native-firebase-tutorial/?fbclid=IwAR2K9boFZVyQY1PvyJZqpCfg-JEFnK-vUfQcKTFaMw8JRfzmbtuAQIhTq2U" rel="nofollow noreferrer">How to Build a React Native App and Integrate It with Firebase</a>. I use the method <strong>Email/Password</strong> for login. I use <strong>Firebase version 9.6.4</strong>.</p>
  <p>I have looked through this thread: <a href="https://github.com/firebase/firebase-js-sdk/issues/2923" rel="nofollow noreferrer">Could not reach Cloud Firestore backend.</a> and tried all the solutions but nothing works for me.</p>
  <p>Any suggestions on what possibly could cause the error and how do I solve it?</p>
  <p><strong>Error message:</strong></p>
  <blockquote>
  <p>[2022-01-29T10:35:40.257Z]  @firebase/firestore:, Firestore (9.6.4):
  Could not reach Cloud Firestore backend. Connection failed 1 times.
  Most recent error: FirebaseError: [code=permission-denied]: Cloud
  Firestore API has not been used in project xxxx before or it
  is disabled.
  If you enabled this API recently, wait a few minutes for
  the action to propagate to our systems and retry. This typically
  indicates that your device does not have a healthy Internet connection
  at the moment. The client will operate in offline mode until it is
  able to successfully connect to the backend.</p>
  </blockquote>
  <p><strong>Firebase <code>config.ts</code> file:</strong></p>
  <pre><code>import firebase from 'firebase/compat/app';
  import 'firebase/compat/auth';
  import 'firebase/compat/firestore';
  
  const firebaseConfig = {
    apiKey: 'XXXXXXXXX',
    authDomain: 'XXXXXXXXX.firebaseapp.com',
    databaseURL: 'https://XXXXXXXXX.firebasedatabase.app',
    projectId: 'XXXXXXXXX',
    storageBucket: 'gs://XXXXXXXXX.appspot.com',
    messagingSenderId: 'XXXXXXXXX',
    appId: 'XXXXXXXXX',
  };
  
  if (!firebase.apps.length) {
      firebase.initializeApp(firebaseConfig);
  }
  
  export { firebase };
  </code></pre>
  <p><strong>LoginScreen.tsx</strong></p>
  <pre><code>import React, { useState } from 'react'
  import { Image, Text, TextInput, TouchableOpacity, View } from 'react-native'
  import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
  import styles from './styles';
  import { firebase } from '../../firebase/config';
  
  export default function LoginScreen({navigation}) {
      const [email, setEmail] = useState('')
      const [password, setPassword] = useState('')
  
      const onFooterLinkPress = () =&gt; {
          navigation.navigate('Registration')
      }
  
      const onLoginPress = () =&gt; {
          firebase
              .auth()
              .signInWithEmailAndPassword(email, password)
              .then((response) =&gt; {
                  const uid = response.user.uid
                  const usersRef = firebase.firestore().collection('users')
                  usersRef
                      .doc(uid)
                      .get()
                      .then(firestoreDocument =&gt; {
                          if (!firestoreDocument.exists) {
                              alert(&quot;User does not exist anymore.&quot;)
                              return;
                          }
                          const user = firestoreDocument.data()
                          navigation.navigate('Home', {user})
                      })
                      .catch(error =&gt; {
                          alert(error)
                      });
              })
              .catch(error =&gt; {
                  alert(error)
              })
      }
  
      return (
          &lt;View style={styles.container}&gt;
              &lt;KeyboardAwareScrollView
                  style={{ flex: 1, width: '100%' }}
                  keyboardShouldPersistTaps=&quot;always&quot;&gt;
                  &lt;Image
                      style={styles.logo}
                      source={require('../../assets/images/logo.png')}
                  /&gt;
                  &lt;TextInput
                      style={styles.input}
                      placeholder='E-mail'
                      placeholderTextColor=&quot;#aaaaaa&quot;
                      onChangeText={(text) =&gt; setEmail(text)}
                      value={email}
                      underlineColorAndroid=&quot;transparent&quot;
                      autoCapitalize=&quot;none&quot;
                  /&gt;
                  &lt;TextInput
                      style={styles.input}
                      placeholderTextColor=&quot;#aaaaaa&quot;
                      secureTextEntry
                      placeholder='Password'
                      onChangeText={(text) =&gt; setPassword(text)}
                      value={password}
                      underlineColorAndroid=&quot;transparent&quot;
                      autoCapitalize=&quot;none&quot;
                  /&gt;
                  &lt;TouchableOpacity
                      style={styles.button}
                      onPress={() =&gt; onLoginPress()}&gt;
                      &lt;Text style={styles.buttonTitle}&gt;Log in&lt;/Text&gt;
                  &lt;/TouchableOpacity&gt;
                  &lt;View style={styles.footerView}&gt;
                      &lt;Text style={styles.footerText}&gt;Don't have an account? &lt;Text onPress={onFooterLinkPress} style={styles.footerLink}&gt;Sign up&lt;/Text&gt;&lt;/Text&gt;
                  &lt;/View&gt;
              &lt;/KeyboardAwareScrollView&gt;
          &lt;/View&gt;
      )
  }
  </code></pre>