Reputation:
I'm using react-native, a formik form, yup validation and firebase authentication. However, I keep getting this error when I try to sign in:
createUser error: [Error: The email address is badly formatted.]
Here's my code: 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=="[email protected]"){
console.log('email not empty')
}
}
Sign In Screen:
createUser(){
FirebaseAPI.createUser(this.state.email, this.state.password)
}
signIn(){
FirebaseAPI.signInUser(this.state.email, this.state.password)
}
Form:
<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)}
/>
This is the result after logging the values:
[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.]
Logging the actual values would give no result so I opted to check if the strings were empty, and it appears that they are. However, when I remove the formik form and use regular Input fields with no validation, everything works fine.
Upvotes: 1
Views: 3092
Reputation: 792
Validate this.state.email
before using it. Refer to this for a similar issue.
Upvotes: 2