I've set up Firebase email/password authentication successfully using firebase-ui.
var uiConfig = {
signInSuccessUrl: '<?php echo $url; ?>',
signInOptions: [
// Leave the lines as is for the providers you want to offer your users.
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
firebase.auth.FacebookAuthProvider.PROVIDER_ID,
firebase.auth.EmailAuthProvider.PROVIDER_ID
],
// Terms of service url.
tosUrl: '<your-tos-url>'
};
// Initialize the FirebaseUI Widget using Firebase.
var ui = new firebaseui.auth.AuthUI(firebase.auth());
// The start method will wait until the DOM is loaded.
ui.start('#firebaseui-auth-container', uiConfig);
but for security reasons I want the user to confirm her/his email.But fromthe above code it doesn't send a verfication mail to user. So I've used following method to send a verification mail to user if he/she not verified his/her account mail.
firebase.auth().onAuthStateChanged(function(user) {
if (user && user.uid != currentUid) {
if (firebase.auth().currentUser.emailVerified) {
currentUid = user.uid;
else {
//---- HERE YOU SEND THE EMAIL
firebase.auth().currentUser.sendEmailVerification();
}
But when I used this code it sends multiple verification mails for same account. Which means this method runs each time a user reload the page. It would be really greatful if someone could help me to identify whether verification mail sent or not for a specific user using firebase.
I found what seems to be a better answer to this barely-documented (for JavaScript) Firebase issue in the sample code here:
// FirebaseUI config.
var uiConfig = {
callbacks: {
signInSuccessWithAuthResult: function(authResult, redirectUrl) {
var user = authResult.user;
...
if (authResult.additionalUserInfo.isNewUser)
{
console.log("new signin");
user.sendEmailVerification();
}
...
return true;
},
enjoy!
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