I have a React web app which has Firebase Auth built in.
Upon a User signing in, I only want the request to successfully complete if the User's email is verified. If it isn't, I want it to error out.
I suspect this will be done through accessing this (taken from the Firebase docs):
var user = firebase.auth().currentUser;
var name, email, photoUrl, uid, emailVerified;
if (user != null) {
name = user.displayName;
email = user.email;
photoUrl = user.photoURL;
emailVerified = user.emailVerified;
uid = user.uid; // The user's ID, unique to the Firebase project. Do NOT use
// this value to authenticate with your backend server, if
// you have one. Use User.getToken() instead.
}
However, I'm unsure if I can implement this in my sign-in flow, so the user doesn't get redirected to their dashboard, before the check is then done. I want it to happen upon submitting the request on the sign in page.
Can someone state how I can tweak this function to build in a check to see if the email is verified, before the user is signed in?
onSubmit = (e) => {
e.preventDefault()
firebase.auth().signInWithEmailAndPassword(this.state.email, this.state.password)
.then(function(response) {
console.log(response);
console.log("Successfully logged in.")
})
.catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorCode);
console.log(errorMessage);
});
this.props.history.push("/dashboard")
}
Or is it only possible to check once the user is signed in? Any help would be appreciated!