【问题标题】: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

标签: javascript android firebase react-native


【解决方案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()

【讨论】:

    猜你喜欢
    • 2021-09-09
    • 2021-05-13
    • 1970-01-01
    • 2023-02-09
    • 2021-08-27
    • 1970-01-01
    • 2021-12-31
    • 2023-02-02
    • 2021-08-24
    相关资源
    最近更新 更多