Reputation: 21
In my code user is created but Email Verification is not working. Here is my code:
const signup = () => {
auth.createUserWithEmailAndPassword(user.email, user.password)
.then((userCredential) => {
// send verification mail.
userCredential.user.sendEmailVerification();
//auth.signOut();
alert("Email sent");
})
.catch(alert);
}
Upvotes: 0
Views: 535
Reputation: 26171
You should wait for the sendEmailVerification
promise to complete before showing the "Email sent" alert as it blocks the thread and prevents the sendEmailVerification
from doing what it needs to.
const signup = () => {
auth.createUserWithEmailAndPassword(user.email,user.password)
.then((userCredential) => {
// send verification mail.
return userCredential.user.sendEmailVerification();
})
.then(() => alert("Email sent"))
.catch((err) => alert(err));
}
Note: Take care in where you call signup
as the browser may be reloading the page before any of the above steps complete because you aren't chaining the Promises. Either return false
to the caller (to prevent the form
element submitting) or the Promise
chain to the caller (to handle success/failure of the actions).
Upvotes: 1