Tengo la siguiente configuración para conectarme a firebase, pero por alguna razón en la consola del navegador muestra que auth.createUserWithEmailAndPassword() no es una función. ¿Hay algo mal con mi código?
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); }) }); editar: auth. from auth.createUserWithEmailAndPassword(email, password).then(cred => { console.log(cred); y ahora me da el error actual: ```Uncaught (en promesa) TypeError: Cannot create property '_canInitEmulator' on cadena 'heheboi@gmail.com'
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) ``Simplemente actualice su código a la versión más reciente de Firebase SDK 9:
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; // .. }); }); Ya está importando createUserWithEmailAndPassword . Ya no puede usar auth.createUserWithEmailAndPassword . Puede encontrar aquí los documentos más recientes.