1

我正在使用 react-native、formik 表单、是的验证和 firebase 身份验证。但是,当我尝试登录时,我不断收到此错误:

createUser 错误:[错误:电子邮件地址格式错误。]

这是我的代码:Firebase API:

export const signInUser = (email, password) => {
console.log('signInUser has been called')
firebase.auth().signInWithEmailAndPassword(email.trim(), password)
    .catch((error) => console.log('signIn error: ', error));
    if (email==""){
        console.log('email empty')
    } 
    if (password==""){
        console.log('password empty')
    }
    if (email=="abc@gmail.com"){
        console.log('email not empty')
    }     

}

登录屏幕:

  createUser(){
    FirebaseAPI.createUser(this.state.email, this.state.password)
  }

  signIn(){
    FirebaseAPI.signInUser(this.state.email, this.state.password)
  }

形式:

<Formik 
          initialValues={{ email: '', password:'' }} 
          onSubmit={(values: FormValues, formikBag: FormikActions<FormValues>) =>
                    this.handleSubmit(values, formikBag)}
          validationSchema= {yupObject().shape({
                    email: yupString()
                    .email("Inavlid email address")
                    .required("This field is required"),
                    password: yupString()
                      .min(8, "Password must be longer than 8 characters")
                      .required("This field is required")
                    })}
        render={(formikBag: FormikProps<FormValues>) => this.renderForm(formikBag)}
      />

这是记录值后的结果:

[09:39:16] signInUser has been called
[09:39:16] email empty
[09:39:16] password empty
[09:39:16] signIn error:  [Error: The email address is badly formatted.]

记录实际值不会给出任何结果,所以我选择检查字符串是否为空,并且看起来它们是空的。但是,当我删除 formik 表单并使用没有验证的常规输入字段时,一切正常。

4

1 回答 1

2

使用前进行验证this.state.email。有关类似问题,请参阅此内容。

于 2019-02-02T19:39:17.190 回答