發生此問題時,我正在嘗試進行電子郵件身份驗證
FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - 呼叫 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 匯入之前,所以現在有什么我遺漏的嗎?
![React Native - FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created](https://img.uj5u.com/2021/11/04/06cb4fb01ca548a49d288ed7bd77f0da.png)
![React Native - FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created](https://img.uj5u.com/2021/11/04/c2c9412099454837bea26b0c8be3f6fa.png)
uj5u.com熱心網友回復:
我建議在配置中初始化和匯出所需的 Firebase 服務,如下所示:
import { initializeApp } from 'firebase/app'
import { getAuth } from 'firebase/auth'
const Fire = initializeApp({...firebaseConfig})
const auth = getAuth(Fire);
export { auth }
您現在可以匯入此auth實體并將其用于createUserWithEmailAndPassword而不是getAuth()在每個組件中使用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/346697.html
標籤:javascript 安卓 火力基地 反应原生
