简体   繁体   中英

How does firebase.auth().createUserWithEmailAndPassword() works?

Weird happens when I try to authenticate new user, the app does not catch any errors but the user is not authenticated however when I debug the code in browser the user gets authenticated. I guess the function terminates before the process of creating a user is finished so when I make the program stop at a brake point while debugging it gives the process enough time to terminate but i don't know how to solve this problem.

               <form>
                   <input type = "text" id = "email" />  
                   <input type = "password" id = "pass" />  
                   <input type = "submit" id = "signup" />  
               </form>
               <script >


      var temail = document.getElementById('email');
      var tpass = document.getElementById('pass');
      var signup = document.getElementById('signup');
      signup.addEventListener('click',e =>{
           var email = temail.value;
           var password = tpass.value;
            firebase.auth().createUserWithEmailAndPassword(email, password)
            .then(function(user){
            console.log(user);
            }).catch(function(error) {
      // Handle Errors here.
      var errorCode = error.code;
      var errorMessage = error.message;
      console.log(errorMessage);
      alert(errorCode);
      // ...
    });
     alert('done');
      }) ;
</script>

I solved this problem by using

<div></div>

instead of

<form></form>

and it worked properly, I don't know why.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM