Firebase控制台未创建新用户

时间:2019-06-17 03:57:58

标签: javascript firebase-authentication

我正在执行用户使用Firebase的注册。为此,我使用“ createUserWithEmailAndPassword(email,password)”方法创建一个新用户。使用Chrome DevTools(调试控制台),我没有发现任何错误。仍然没有在我的控制台中创建新用户。

我对元素的HTML代码如下:

<section id="first_part_page">

        <form id="Subscribe_Form">

            <input class="input_box" id="email_input" type="text" placeholder="Email">
            <br>
            <input class="input_box" id="input_password" type="text" placeholder="Password">
            <br>
            <input class="main_button" type="submit" id="submit_form" value="Submit" onclick="subscribeFirebase()"> 
        </form>
    </section> 

我在页面中添加了以下脚本。

        

    <!-- TODO: Add SDKs for Firebase products that you want to use
      https://firebase.google.com/docs/web/setup#config-web-app -->
    <script src="https://www.gstatic.com/firebasejs/6.1.1/firebase-auth.js"></script>
    <script src="https://www.gstatic.com/firebasejs/6.1.1/firebase-firestore.js"></script>

    <script src="js/firebase_subscribe.js"></script>

在上一个脚本“ js / firebase_subscribe.js”中,我包含了以下代码:

//Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "xxxxxx",
authDomain: "xxxxxx",
databaseURL: "xxxxxx",
projectId: "xxxxxx",
storageBucket: "xxxxxx",
messagingSenderId: "xxxxxx",
appId: "xxxxxx"
};

// Initialize Firebase
firebase.initializeApp(firebaseConfig);

//function that handles the subscribe process 
function subscribeFirebase(){

var user_Email = document.getElementById("email_input").value;
var user_Password = document.getElementById("input_password").value;

console.log(user_Email + user_Password);

//new user does not appear in firebase console 

firebase.auth().createUserWithEmailAndPassword(user_Email, user_Password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorMessage);
// ...
});    
}

我没有错误消息,一切似乎都正常。我的控制台中什么也没有显示。因此,不会创建新用户。知道这怎么可能吗?

1 个答案:

答案 0 :(得分:0)

尝试此代码。如果您不想将详细信息保存到db中,请删除代码中的存储部分。

firebase.auth().createUserWithEmailAndPassword(Email1,password).then(function(user) { // it create a new user starting point of create user
            user.sendEmailVerification().then(function() { // it send verification mail to the respective user
             console.log("verification email sent"); 
             var db = firebase.firestore();
               db.collection("Users").doc(firebase.auth().currentUser.uid).set({
               FirstName :  Firstname,
               LastName : lastname,
               Email : Email1,
               PhoneNumber : phonum
             }).then(function() {
               alert("Document successfully written!");
               }).catch(function(error){  // for when document is not correctly wrote
                alert("Got an error",error); 
                 });// end of the firestore data

             }).catch(function(error) {// for when verification email is not sent to respective mails
            alert(error.message);
            alert(error.code);
            });// end of verification mail
             }).catch(function(error) // error occur when new user is already registered
             {
               alert(error.message);
               alert(error.code);
             }); //end of create user method