我知道已经有几个问题讨论了这种错误,但是它们似乎都没有提供正确的解决方案。我正在跟随 Stephen Grider 在 Udemy 上的 React Native 课程。
我相当确定我已经完全按照教程操作了,所以我猜测问题可能与 React 或 Firebase 的更新或其他原因有关,但我也可能完全错了。当按下激活以下代码的按钮时:
state = { email: '', password: '', error: '' };
//a definition of the component's state, updated with onChangeText
onButtonPress() {
const { email, password } = this.state;
this.setState({ error: ' ' });
firebase.auth().signInWithEmailAndPassword(email, password) //this line is a "promise"
.catch(() => { //if it fails:
firebase.auth().creatUserWithEmailAndPassword(email, password) //also returns a promoise
.catch(() => { //if it also fails to create a username and password:
this.setState({ error: 'Authentication Failed.' });
});
});
}
我遇到了以下错误: 由于网络上很多处理此错误的解决方案都与Firebase初始化有关,因此这里是我的代码:
import React, { Component } from 'react';
import { View } from 'react-native';
import firebase from 'firebase';
import { Header } from './components/common/index.js'; //selects index.js automatically
import LoginForm from './components/LoginForm.js';
class App extends Component {
conponentWillMount() {
//called before render, will automatically be called because it's a life cycle method
firebase.initializeApp({
apiKey: '(I actually have my api key here, I just do not want people to steal it, same with the other values)',
authDomain: 'authenticationtutorial-ee660.firebaseapp.com',
databaseURL: 'my databaseURL',
projectId: 'my projectId',
storageBucket: 'authenticationtutorial-ee660.appspot.com',
messagingSenderId: 'my SenderId'
});
}
render() {
return (
<View>
<Header headerText="Authentication" />
<LoginForm />
</View>
);
}
}
export default App;
有任何帮助将不胜感激。我已经忙碌了一个星期,处理这个错误,但在Udemy网站上没有得到任何帮助,所以我转向 Stack Overflow :)
App
中的componentWillMount
拼写为conponentWillMount
,第三个字母是n
,但如果这不是问题,我在这里看不出任何错误。你是否在 Firebase 上启用了登录方法?如果没有,请前往项目->身份验证,然后启用电子邮件登录,这是第一个选项。 - K.Wureact
和react-native
复现相同的错误,但失败了。 - K.Wu