onSubmit(formData) {
if(formData.valid) {
console.log(formData.value);
this.af.auth.createUser({
email: formData.value.email,
password: formData.value.password
}).then(
authState => {
authState.auth.sendEmailVerification();
this.router.navigate(['/login'])
}).catch(
(err) => {
console.log(err);
this.error = err;
})
}
}
In Firebase, I set the SendEmailVerfication
like the code above, and the email could send normally.However, in my app, there is no difference between the user who does not click the verification email with those clicked, how to make a difference?
Check verification statusinitializeApp(config); firebase. auth(). onAuthStateChanged( function(user) { if(user){ var emailVerified = user. emailVerified; var email = user.
var user = firebase. auth(). currentUser; if (user) { // User is signed in. } else { // No user is signed in. }
Email and password based authenticationAuthenticate users with their email addresses and passwords. The Firebase Authentication SDK provides methods to create and manage users that use their email addresses and passwords to sign in. Firebase Authentication also handles sending password reset emails.
You can use firebase.auth().currentUser.emailVerified
This will return true
or false
.
- If you are already loggedIn below solutions can help you to check email verified status.
1) The recommended way to get the current user is by setting an observer on the Auth object:
firebase.auth().onAuthStateChanged(authUser => {
if(authUser.user.emailVerified){ //This will return true or false
console.log('email is verified')
}else{
console.log('email not verified')
}
})
2) You can also get the currently signed-in user by using the currentUser property.
var user = firebase.auth().currentUser;
if (user.emailVerified) {
// email is verified.
} else {
// email is not verified.
}
- If you are not loggedIn then please try below solution.
firebase.auth().signInWithEmailAndPassword(email, password ).then(authUser => {
if(authUser.user.emailVerified){ //This will return true or false
console.log('email is verified')
}else{
console.log('email not verified')
}
}).catch(function(error) {
});
According to the documentation, the User
object contains an emailVerified
property.
So the user to which the signInWithEmailAndPassword
method's promise resolves - or the user that is passed to the onAuthStateChanged
method's callback - can be inspected and the value of emailVerified
can be checked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With