Firebase - Auth - find users who have registered but have not verified an email address

I installed the Firebase project that I use for this user authentication module. I also use the firebaseui-web project from Github.

My login redirect works fine in this code:

// FirebaseUI config.
var uiConfig = {
  'signInSuccessUrl': 'MY_REDIRECT.html',
  'signInOptions': [
    firebase.auth.EmailAuthProvider.PROVIDER_ID
  ],
  // Terms of service url.
  'tosUrl': '<your-tos-url>',
};

When the page loads (i.e. MY_REDIRECT.html), I check the status of the user to see if he checks his email, and if not, then call the sendEmailVerification method :

checkLoggedInUser = function() {
  auth.onAuthStateChanged(function(user) {
    if (user) {
      // is email verified
      if(user.emailVerified) {
        // show logged in user in UI
        $('#loggedinUserLink').html('Logged in:' + user.email + '<span class="caret"></span>');        
      } else {
        // user e-mail is not verified - send verification mail and redirect
        alert('Please check your inbox for a verification e-mail and follow the instructions');
        // handle firebase promise and don't redirect until complete i.e. .then
        user.sendEmailVerification().then(function() {
          window.location.replace('index.html');
        });
      }
    } else {
      // no user object - go back to index
      window.location.replace("index.html");
    }
  }, function(error) {
    console.log(error);
  });
};

window.onload = function() {
  checkLoggedInUser()
};

Everything is fine so far - Firebase does what I want! Thanks guys:)

Firebase Console , , . :

enter image description here

, UID .

, - ? (, , , ) Auth? UID ( emailVerified). , , , - .

+4
1

Firebase , . API , , .

, :

firebase.auth().currentUser.emailVerified

, . , () . :

{
  "rules": {
    ".read": "auth != null && auth.token.email_verified",
    "gmailUsers": {
      "$uid": {
        ".write": "auth.token.email_verified == true && 
                   auth.token.email.matches(/.*@gmail.com$/)"
      }
    }
  }
}

, , gmail gmailUsers.

+7

All Articles