ok, he estado construyendo un clon de discordia con reaccionar redux, ahora mismo estoy atascado en la página de inicio de sesión. sigue dándome este error "Error de tipo no detectado: firebase__WEBPACK_IMPORTED_MODULE_0 _.app.auth no es una función" aquí está mi código en firebase.js
import { initializeApp } from "firebase/app"; import { getDatabase } from 'firebase/database'; import { getAuth } from "firebase/auth" import { GoogleAuthProvider } from "firebase/auth"; const firebaseConfig = { apiKey: "AIzaSyD0RxEfG1qZ4Qsoelw5E6J0rIaJSP4BbXQ", authDomain: "diacromb.firebaseapp.com", projectId: "diacromb", storageBucket: "diacromb.appspot.com", messagingSenderId: "237625612351", appId: "1:237625612351:web:2527b57f858d5a4688008a", measurementId: "G-3DEREK47Q2" }; // Initialize Firebase const app = initializeApp(firebaseConfig); const db = getDatabase(app); const auth = getAuth(); const provider = new GoogleAuthProvider(); export {auth , app }; export {provider}; export default db;aquí está mi código para Login.js
import { Button } from '@material-ui/core' import { auth, app } from './firebase' import { provider } from './firebase' import { signInWithPopup } from "firebase/auth" import React from 'react' import './Login.css' function Login() { /* const signIn = () =>{ const googleAuthProvider = new GoogleAuthProvider(); app.auth().signInWithPopup(googleAuthProvider); } */ const signIn = ()=>{ var google_provider = provider; app.auth().signInWithPopup(provider) .then((re)=>{ console.log(re) }) .catch((err)=>{ console.log(err) }) } return ( <div className='login'> <h2> I am the login page</h2> <Button onClick={signIn}>Sign In</Button> </div> ); } export default LoginNo tengo idea de lo que está pasando, he leído algunas otras publicaciones y la gente dice que instale versiones anteriores de firebase, traté de hacer eso y todavía no funcionó. He estado perplejo en esto durante casi 2 días ahora
Supongo que está usando firebase 9. allí tiene que usar los módulos js.
https://firebase.google.com/docs/web/modular-upgrade
import { getAuth, signInWithPopup, GoogleAuthProvider } from "firebase/auth"; const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // This gives you a Google Access Token. You can use it to access the Google API. const credential = GoogleAuthProvider.credentialFromResult(result); const token = credential.accessToken; // The signed-in user info. const user = result.user; // ... }).catch((error) => { // Handle Errors here. const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. const email = error.email; // The AuthCredential type that was used. const credential = GoogleAuthProvider.credentialFromError(error); // ... });