【发布时间】:2017-11-07 04:33:48
【问题描述】:
我构建了一些身份验证应用程序,包括在 firebase 上输入用户名、密码。但是在我按下应用程序上的登录按钮后什么也没有发生。它只显示“身份验证失败”。
class LoginForm extends Component {
state = {
email: '',password: '',error: '',loading: false
};
onButtonPress() {
const { email, password } = this.state;
this.setState({ error: '', loading: true });
firebase.auth().signInWithEmailAndPassword(email, password)
.then(this.onLoginSuccess.bind(this))
.catch(() => {
firebase.auth().createUserWithEmailAndPassword(email, password)
.then(this.onLoginSuccess.bind(this))
.catch(this.onLoginFail.bind(this));
});
}
onLoginFail() {
this.setState({ error: 'Authentication Failed.', loading: false });
}
onLoginSuccess() {
this.setState({
email: '',password: '',error: '',loading: false});
}
render
....
value={this.state.email}
onChangeText={email => this.setState({ email })}
/>
</CardSection>
<CardSection>
<Input
...
onChangeText={password => this.setState({ password })}
/>
【问题讨论】:
-
你可以通过你的 catch 块传递一个错误来调试它,比如
catch(error => {console.log(error);}- 让我们知道错误是什么
标签: javascript firebase react-native firebase-authentication