如何登录仅验证了电子邮件的用户

时间:2017-09-10 13:18:28

标签: javascript firebase web firebase-authentication

我有一个允许用户注册或创建帐户的功能。它还在注册后发送验证。我只希望验证电子邮件的用户登录。我该怎么办?

这是我的登录功能。

   function signIn() {
   var email = $("#emailtxt").val();
   var password = $("#passwordtxt").val();
   var auth = firebase.auth();        

   firebase.auth().signInWithEmailAndPassword(email, 
   password).then(function(value) {
      //NEED TO PULL USER DATA?                     

      var user = firebase.auth().currentUser;
      if(user){
        console.log(user.uid);
        $("#popup").click();
      }
    }).catch(function(error) {
   // Handle Errors here.
   var errorCode = error.code;
   var errorMessage = error.message;
   if (errorCode === 'auth/wrong-password') {
     alert('Wrong password.');
   } else {
    alert(errorMessage);
  }
  console.log(error);
});
     }

1 个答案:

答案 0 :(得分:0)

我希望你可以使用console.log来保存当前用户

var user = firebase.auth().currentUser;
console.log(user); //there you can see emailVerified boolean object will be available.
if(user.emailVerified){
   // then you can allow your users to be logged in your site.

}
else if(!user.emailVerified){ //send a emailverification mail to the user
  firebase.auth().currentUser.sendEmailVerification().then(function() {
    alert('Email Verification Sent!');
  });

}

added a picture of user mail verified or not