Necesito ayuda, estaba viendo un tutorial para firebase y react. y luego me di cuenta de que el tutorial era para v8 y el más nuevo es v9
este es mi base de fuego.js
import { initializeApp } from 'firebase/app'; import { getAuth } from 'firebase/auth'; import { getDatabase } from "firebase/database"; const firebaseConfig = { //firebaseconfig }; const app = initializeApp(firebaseConfig); const auth = getAuth(app); const database = getDatabase(app); export { auth, database }y luego este es mi código de fragmento signin.js
import { auth, database } from "../Firebase/firebase"; const submitForm = async (values) => { auth() .signInWithEmailAndPassword(values.email,values.password) .then((userCredentials) => { props.history.push("/profile"); }).catch((err) => { setLoading(false); }); };y luego, cuando envío mi formulario, la aplicación se bloquea con un error en la autenticación ().
Unhandled Rejection (TypeError): Object(...) is not a functionimport { auth, database } from "../Firebase/firebase"; // this ^^^^ is not a function but is being used as one // auth().signInWithEmailAndPassword(values.email,values.password) // ^^^^ here signInWithEmailAndPassword debe importarse desde firebase/auth como se muestra a continuación:
import { auth, database } from "../Firebase/firebase"; import { signInWithEmailAndPassword } from "firebase/auth" const submitForm = async (values) => { const userCredentials = await signInWithEmailAndPassword(auth, values.email, values.password) // Pass the 'auth' instance here ^^^^ const { user: { uid } } = userCredentials console.log(`userId: ${uid}`) }Recomiendo seguir la documentación junto con cualquier tutorial. La documentación tiene una sintaxis de espacio de nombres (v8) y modular/funcional (v9).