繁体   English   中英

.then((userCredential) => { } 不使用 firebase 身份验证

[英].then((userCredential) => { } not working with firebase authentification

我正在开发一个 web 应用程序(初学者级别),我使用 firebase 进行身份验证和数据库。 我可以创建一个新帐户并在我的 firebase 身份验证仪表板上注册它而不会出现问题,但里面没有任何内容。then((userCredential) => { } 正在工作(警报不显示,我无法在 firebase 数据库上注册帐户等....我检查了 chrome 控制台,没有显示任何错误,我也没有来自 .catch 的错误消息。我该如何解决这个问题,所以里面的内容.then 正在工作?谢谢!

import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.15.0/firebase-app.js' 
import { getAuth, createUserWithEmailAndPassword } from 'https://www.gstatic.com/firebasejs/9.15.0/firebase-auth.js'
import { getFirestore, doc, getDoc, getDocs, collection } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-firestore.js";
import { getDatabase, ref, set } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-database.js";


const firebaseConfig = {
    apiKey: "",
    authDomain: "",
    databaseURL: "",
    projectId: "",
    storageBucket: "",
    messagingSenderId: "",
    appId: "" 
  };


const app = initializeApp(firebaseConfig);
const db = getFirestore();
const auth = getAuth(); 
const database = getDatabase()


submitData.addEventListener('click', (e) => {
    var name = document.getElementById('full_name').value
    var email = document.getElementById('email').value;
    var password = document.getElementById('psw').value;
    alert(email)
    // do verification




    // Move on with Auth
    createUserWithEmailAndPassword(auth, email, password)
    .then((userCredential) => {

      const user = userCredential.user
      alert("user created")
    })
    
    .catch(function(error) {
      // Firebase will use this to alert of its errors
      var error_code = error.code
      var error_message = error.message

       alert(error_message)
      alert('not working')
    })
})

如果您使用的是form元素,则只需使用e.preventDefault()来停止页面重新加载,将其放在变量之前。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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