这就是我调用 firebase auth 的方式:
onButtonPress() {
const {email, password} = this.state;
console.log(email,password);
firebase.auth().signInWithEmailAndPassword(email, password)
.catch( (err) => {
console.log(err);
firebase.auth().createUserWithEmailAndPassword(email, password)
.catch( (err) => {
console.log(err);
this.setState({ error: err.message });
});
});
}
这是我的身份验证文本输入:
<Card>
<CardSection>
<Input
secureTextEntry={false}
label={'E-mail'}
placeholder={'user@gmail.com'}
onChangeText={(email) => this.setState({email})}
value={this.state.email}
/>
</CardSection>
<CardSection>
<Input
secureTextEntry={true}
label={'Password'}
placeholder={'password'}
onChangeText={(password) => this.setState({password})}
value={this.state.password}
/>
</CardSection>
<Text style={styles.errorStyle}>{this.state.error}</Text>
<CardSection>
<Button onPress={this.onButtonPress.bind(this)}>
Log In
</Button>
</CardSection>
</Card>
但是当它运行时,它会向我显示如下消息:
即使我没有在输入中输入任何电子邮件和密码并按提交,也会弹出此错误。
最佳答案
该错误是由于 this.state.email 导致的默认空间而发生的。使用 trim() 并将其发送到服务器阻止了错误的发生。这是一段工作代码。
const {email, password} = this.state;
this.setState({ error: '', loading: true });
firebase.auth().signInWithEmailAndPassword(email.trim(), password)
.then(this.onLoginSuccess.bind(this))
.catch( (err) => {
firebase.auth().createUserWithEmailAndPassword(email.trim(), password)
.then(this.onLoginSuccess.bind(this))
.catch(this.onLoginFailed.bind(this));
});
关于firebase - “电子邮件格式错误”react-native firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47727045/