Firebase:电子邮件格式错误

时间:2019-02-02 18:27:03

标签: javascript react-native firebase-authentication formik yup

我使用反应本地的,一个formik形式,烨验证和火力验证。但是,尝试登录时始终出现此错误:

  

的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形式和使用普通的输入字段没有确认,一切工作正常。

1 个答案:

答案 0 :(得分:2)

在使用之前验证this.state.email。有关类似问题,请参见this