5

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?

Mateus99
  • 119
  • 1
  • 2
  • 9
  • It sounds like you didn't fully follow the instructions for adding Firebase to your app. – Doug Stevenson Jan 13 '20 at 18:18
  • Simple. 1. apply plugin: 'com.google.gms.google-services'. Add this is at the bottom of the page in android=>app=>build.gradle 2. Make sure your android project name in Firebase matches with the project name in AndroidManifest.xml. 3. Go to Virtual device manager in android studio, click dropdown of the active Emulator and click wipe data. 4. cd android &&./gradlew clean && cd .. 5. npm start. Happy coding!!!! – M.Kalidass Jun 08 '22 at 17:34

1 Answers1

-7

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

tomerpacific
  • 4,704
  • 13
  • 34
  • 52