firebase - “电子邮件格式错误”react-native firebase

标签 firebase react-native

这就是我调用 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>

但是当它运行时,它会向我显示如下消息:

enter image description here

即使我没有在输入中输入任何电子邮件和密码并按提交,也会弹出此错误。

最佳答案

该错误是由于 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/

相关文章:

firebase - 如何允许用户查询集合但只能访问集合中的某些结果?

ios - 如何使用 Firebase 和 Swift 将现有节点添加到具有不同父节点的另一个节点作为引用?

ios - 获取对等依赖错误 react / react native

react-native - 如何检测 native react 中的循环依赖项导入?

javascript - 无法在我的组件中调用 redux 操作

firebase - Cloud Firestore上一组对象的数组vs. map vs.子集合

javascript - firebase onwrite 的云函数不触发任何执行

android - Play-services 15.0 不支持 MapView.getMap()

javascript - 如何在React Native中设置键盘上方的TextInput

android - react native : ReferenceError: Can't find variable: require (line 1 in the generated bundle)