Firebase-ui to check email

I have successfully set up Firebase email / password authentication 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 his / her email address. But from the above code, it doesn't send a validation message to the user. Thus, I used the following method to send a verification mail to the user if he / she has not verified his / her account.

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 emails for one account. This means that this method is run every time the user reloads the page. It would be very helpful if someone could help me determine if a mailing list was sent or not to a specific user using firebase.

+3


source to share





All Articles