quiero usar la autenticación de base de fuego, así que declaré una autenticación con nombre constante en mi script de cuerpo html y quería usarla en mi archivo auth.js pero dice que no está definido y quiero saber cómo resolver el problema. este es el código que escribí: este es el código en mi archivo html:
<!-- Firebase --> <script type="module"> // Import the functions you need from the SDKs you need import { initializeApp } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-app.js"; import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-analytics.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: Add SDKs for Firebase products that you want to use // Your web app's Firebase configuration // For Firebase JS SDK v7.20.0 and later, measurementId is optional const firebaseConfig = { apiKey: "AIzaSyC3GLIN5TBmCDoTfy0dEOgOdvVvqNw-ric", authDomain: "auth-project-38aaa.firebaseapp.com", projectId: "auth-project-38aaa", storageBucket: "auth-project-38aaa.appspot.com", messagingSenderId: "431888894254", appId: "1:431888894254:web:71bb9b250fbb8a21edd2bf", measurementId: "G-6BBPCJ3814" }; // Initialize Firebase const app = initializeApp(firebaseConfig); const analytics = getAnalytics(app); const auth = getAuth(app); const db = getFirestore(app); </script> <!-- JS --> <script src="vendor/jquery/jquery.min.js"></script> <script src="js/auth.js"></script>y este es el código en mi auth.js:
const signUpForm = document.querySelector('#register-form'); signUpForm.addEventListener('submit', (e) => { e.preventDefault(); // get user info const name = signUpForm['name'].value; const email = signUpForm['email'].value; const pass = signUpForm['pass'].value; const rePass = signUpForm['re_pass'].value; const agreeTerm = signUpForm['agree-term'].value; console.log(name, email, pass, rePass, agreeTerm); // sign up the user auth.createUserWithEmailAndPassword(email, pass).then(cred => { console.log(cred); }); });El auth.createUserWithEmailAndPassword es para Firebase SDK v8 y anterior, o para el modo de compatibilidad en v9.
La nueva sintaxis está de acuerdo con la documentación sobre la creación de un usuario :
createUserWithEmailAndPassword(auth, email, pass).then(cred => { ... });