React Native - FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created

Posted

技术标签:

【中文标题】React Native - FirebaseError: Firebase: No Firebase App \'[DEFAULT]\' has been created【英文标题】:React Native - FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been createdReact Native - FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created 【发布时间】:2021-12-16 19:26:56 【问题描述】:

发生此问题时,我正在尝试进行电子邮件身份验证

FirebaseError:Firebase:没有创建 Firebase 应用“[DEFAULT]” - 调用 Firebase App.initializeApp() (app/no-app)。

从我读到的东西,人们说这个问题是关于时间问题,但我不确定我的应用程序中这个错误的原因是什么

import React from 'react';
import ScrollView, StyleSheet, Text, View from 'react-native';
import Button, Gap, Input from '../../components/atoms';
import Fire from '../../config';
import Header from '../../components/molecules';
import useForm from '../../utils';

import getAuth, createUserWithEmailAndPassword from 'firebase/auth';

export default function Register() 
  const [form, setForm] = useForm(
    fullName: '',
    bloodType: '',
    email: '',
    password: '',
  );

  const onContinue = () => 
    console.log(form);
    const auth = getAuth();
    createUserWithEmailAndPassword(auth, form.email, form.password)
      .then(success => 
        // Signed in
        console.log('register success: ', success);
        // ...
      )
      .catch(error => 
        const errorMessage = error.message;
        console.log('error register: ', errorMessage);
        // ..
      );
  ;

  return (
    <View>
      <Header title="Register User" />
      <View style=styles.content>
        <ScrollView showsVerticalScrollIndicator=false>
          <Input
            label="Full Name"
            value=form.fullName
            onChangeText=value => setForm('fullName', value)
          />
          <Gap height=24 />
          <Input
            label="Golongan Darah"
            value=form.bloodType
            onChangeText=value => setForm('bloodType', value)
          />
          <Gap height=24 />
          <Input
            label="Email"
            value=form.email
            onChangeText=value => setForm('email', value)
          />
          <Gap height=24 />
          <Input
            label="Password"
            value=form.password
            onChangeText=value => setForm('password', value)
            secureTextEntry
          />
          <Gap height=40 />
          <Button title="Register" onPress=onContinue />
        </ScrollView>
      </View>
    </View>
  );

我将我的配置(Fire)放在 getAuth 导入之前,所以我现在有什么遗漏吗?

【问题讨论】:

你能分享一下配置文件(从哪里导入 Fire)吗?我建议在同一个文件中初始化身份验证并从那里导出。 我把配置ss放在底部@Dharmaraj 【参考方案1】:

我建议在配置中初始化和导出所需的 Firebase 服务,如下所示:

import  initializeApp  from 'firebase/app'
import  getAuth  from 'firebase/auth'

const Fire = initializeApp(...firebaseConfig)

const auth = getAuth(Fire);

export  auth 

您现在可以导入此auth 实例并将其与createUserWithEmailAndPassword 一起使用,而不是在每个组件中使用getAuth()

【讨论】:

以上是关于React Native - FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created的主要内容,如果未能解决你的问题,请参考以下文章

react native 增加react-native-camera

更新 react-native-maps 以使用 create-react-native-app

react native 增加react-native-storage

React-Native 和 Expo:create-react-native-app 和 react-native init 之间的区别

什么是 react-native-cli 和 @react-native-community/cli?

React Native - 当 react-native 版本 > 0.55 时,无法通过 react-native-cli 创建新项目