本文介绍了auth.createUserWithEmailAndPassword不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下设置来连接到Firebase,但是由于某种原因,在浏览器控制台中它显示auth.createUserWithEmailAndPassword()
不是一个函数。我的代码有问题吗? import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.0.2/firebase-app.js';
import { getAuth, createUserWithEmailAndPassword } from 'https://www.gstatic.com/firebasejs/9.0.2/firebase-auth.js';
import { getFirestore } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-firestore.js"
// TODO: Replace the following with your app's Firebase project configuration
const firebaseConfig = {
" my config here "
};
const app = initializeApp(firebaseConfig);
const auth = getAuth();
const db = getFirestore();
var button = document.getElementById("button").addEventListener("click", function () {
var email = document.getElementById("email").value;
var phone = document.getElementById("phone").value;
var password = document.getElementById("password").value;
auth.createUserWithEmailAndPassword(email, password).then(cred => {
console.log(cred);
})
});
编辑:我从auth.createUserWithEmailAndPassword(email, password).then(cred => { console.log(cred);
中删除了auth.
,现在它给出了当前错误:`Uncatch(In Promise)TypeError:Cannot Create Property字符串‘[email protected]’上的‘_canInitEmulator’at _performFetchWithErrorHandling (firebase-auth.js:1983)
at _performApiRequest (firebase-auth.js:1958)
at _performSignInRequest (firebase-auth.js:2030)
at signUp (firebase-auth.js:5330)
at createUserWithEmailAndPassword (firebase-auth.js:5978)
at HTMLButtonElement.<anonymous> (register.html:48) ``
推荐答案
只需将您的代码更新到最新的Firebase SDK9:
import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.0.2/firebase-app.js';
import { getAuth, createUserWithEmailAndPassword } from 'https://www.gstatic.com/firebasejs/9.0.2/firebase-auth.js';
import { getFirestore } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-firestore.js"
// TODO: Replace the following with your app's Firebase project configuration
const firebaseConfig = {
" my config here "
};
const app = initializeApp(firebaseConfig);
const auth = getAuth();
const db = getFirestore();
var button = document.getElementById("button").addEventListener("click", function () {
var email = document.getElementById("email").value;
var phone = document.getElementById("phone").value;
var password = document.getElementById("password").value;
createUserWithEmailAndPassword(auth, email, password).then(cred => {
console.log(cred);
}).catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
// ..
});
});
您已经在导入createUserWithEmailAndPassword
。您不能再使用auth.createUserWithEmailAndPassword
。您可以找到here最新文档。 这篇关于auth.createUserWithEmailAndPassword不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!