【问题标题】:Firebase console no new user createdFirebase 控制台未创建新用户
【发布时间】:2019-10-30 15:32:37
【问题描述】:

我正在使用 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);
// ...
});    
}

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

【问题讨论】:

  • 您能否在createUserWithEmailAndPassword 方法中添加.then 方法来检查Firebase 是否真的在创建该用户?您是否还检查了是否在 Firebase 控制台中启用了电子邮件身份验证?
  • 您好 Edric,我已启用电子邮件身份验证.. 如何添加 .then 方法?

标签: javascript firebase-authentication


【解决方案1】:

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

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 

【讨论】:

  • 嗨,“vijju”,请考虑解释一下你对 OP 提供的代码做了什么,而不是从 sn-p 复制。
  • 我写了 cmets 解释每一行发生了什么
猜你喜欢
  • 1970-01-01
  • 2019-01-31
  • 2016-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-12
相关资源
最近更新 更多