【问题标题】:Error: No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp() [duplicate]错误:没有创建 Firebase 应用“[DEFAULT]”-调用 firebase.initializeApp() [重复]
【发布时间】:2020-04-30 11:25:09
【问题描述】:

我需要使用带有 Firebase 的电话身份验证,但是每次我单击将代码发送给用户的按钮时都会显示此错误,这可能很容易解决,但由于我对 firebase 和 react native 的了解不是很深,我找不到解决办法。

这是我的代码:

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>

        )
    }
}

我想我需要在我的代码中的某处插入这个“firebase.initializeApp()”。请问,我该如何解决这个问题?

【问题讨论】:

  • 听起来您没有完全按照说明将 Firebase 添加到您的应用。

标签: firebase react-native firebase-authentication


【解决方案1】:

这个错误很简单,如果你看一下documentation,你会发现你需要一个firebaseConfig对象,

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",
    };

你的应用程序的所有相关数据,然后你需要使用命令:

firebase.initializeApp(firebaseConfig);

这通常插入到您的App.js 文件中

【讨论】:

  • 对于 ios 可能是什么问题
  • @NithyanandanSathiyanathan - 请用代码和更多解释发布另一个问题。
  • react-native 不支持 firebase javascript-SDK
  • 正如@PratapSharma 所暗示的,React Native Firebase 项目和 Google 自己的 Firebase 项目之间存在差异,尽管它们都有 JavaScript 接口。这个错误涉及 React Native 和 iOS。
猜你喜欢
  • 2020-12-24
  • 2021-12-29
  • 1970-01-01
  • 2020-05-21
  • 1970-01-01
  • 2023-01-20
  • 2020-12-12
相关资源
最近更新 更多