Error: No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp()

21,105

The error is pretty straight forward and if you take a look at the documentation, you can see that you need to have a firebaseConfig object,

var firebaseConfig = {
      apiKey: "api-key",
      authDomain: "project-id.firebaseapp.com",
      databaseURL: "https://project-id.firebaseio.com",
      projectId: "project-id",
      storageBucket: "project-id.appspot.com",
      messagingSenderId: "sender-id",
      appId: "app-id",
      measurementId: "G-measurement-id",
    };

with all the relevant data for your application and then you need to use the command:

firebase.initializeApp(firebaseConfig);

This is usually inserted inside your App.js file

Share:
21,105
Mateus99
Author by

Mateus99

Updated on January 14, 2020

Comments

  • Mateus99
    Mateus99 over 4 years

    I need to use Phone authentication with firebase but every time I click on the button that sends the code to the user this error shows up, it's probably easy to solve but since my knowledge with firebase and react native is not very deep I can't find a solution.

    Here is my code:

    export default class VerifyCell extends Component{
        static navigationOptions = {header: null}
    
        constructor(props){
            super(props);
            this.state = {
                code: '',
            };
        }
    
        render(){
    
            const celular = this.props.navigation.getParam('celular');
    
            return (
                <ScrollView style={styles.container}>
                    <HeaderIcon type='MaterialCommunityIcons' name='message-processing'/>
                        <Text style={styles.titulo}>Phone Verification</Text>
                        <Text style={styles.dica}>Insert the code that has been sent to you below</Text>
    
                        <FormItem onChangeText={ (code) => this.setState({code}) } texto='Code'/>
    
    
                        <View style={{marginBottom: '40%'}}></View>
    
                        <GradientButton texto='Send code' onPress={async () => {
                            const confirmation = await auth().signInWithPhoneNumber('+55 19995661551');
                        }}/>
    
    
                    <View style={styles.formButton}>
    
                         <GradientButton texto='Next' onPress={async () => {
                             try {
                                await confirmation.confirm(this.state.code); // User entered code
                                // Successful login - onAuthStateChanged is triggered
                              } catch (e) {
                                console.error(e); // Invalid code
                              }
                             this.props.navigation.navigate('CadastraDados', {celular: celular} )
                             }}/>
                    </View>
    
                </ScrollView>
    
            )
        }
    }
    

    I guess I need to insert this "firebase.initializeApp()" somewhere in my code. Please, how can I fix this issue?

  • Nithyanandan Sathiyanathan
    Nithyanandan Sathiyanathan almost 4 years
    for ios what could be the problem
  • tomerpacific
    tomerpacific almost 4 years
    @NithyanandanSathiyanathan - please post another question with code and more explanation.
  • Pratap Sharma
    Pratap Sharma over 3 years
    react-native does not support firebase javascript-SDK
  • haleonj
    haleonj almost 3 years
    As @PratapSharma suggests, there is a difference between the React Native Firebase project and Google's own Firebase project, despite both having a JavaScript interface. This bug concerns React Native and iOS.