Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
FIREBASE - ReferenceError: no se puede acceder a 'auth' antes de la inicialización

estoy en el medio para aprender Auth con Firebase usando NextJS , tratando de entender usando múltiples fuentes (artículo / youtube) pero estoy atascado con este error

ReferenceError: Cannot access 'auth' before initialization

Honestamente, todavía estoy tratando de encontrar the source pero sigo atascado.

Aquí está mi firebase.js

 import { firebase, initializeApp } from "firebase/app"; import { getAnalytics } from "firebase/analytics"; const firebaseConfig = { apiKey: process.env.APIKEY, authDomain: process.env.AUTH, projectId: process.env.PID, storageBucket: process.env.BUCKET, messagingSenderId: process.env.MSID, appId: process.env.AID, measurementId: process.env.MID, }; const app = !firebase.apps.length ? initializeApp(firebaseConfig) : firebase.app(); const analytics = getAnalytics(app); const auth = app.auth(); const db = app.firestore(); const googleProvider = new firebase.auth.GoogleAuthProvider(); export { auth, db, signInWithGoogle, ... };

y esta es mi página login.js

 import React, { useEffect, useState } from "react"; import { auth, signInWithEmailAndPassword, signInWithGoogle, } from "../../firebase/index"; import Link from "next/link"; import { useAuthState } from "react-firebase-hooks/auth"; function Login() { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [user, loading, error] = useAuthState(auth); useEffect(() => { if (loading) { // maybe trigger a loading screen return; } if (user) { alert("GET USER"); console.log(user); } }, [user, loading]); return ( ...

Estoy usando

 "firebase": "^9.6.1", "firebase-admin": "^10.0.1",

¿Estoy haciendo algo mal? ¿O me estoy perdiendo algo? por favor ayuda:(

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe importar getAuth() desde Firebase Auth SDK y luego inicializarlo como se muestra a continuación:

 import { initializeApp } from "firebase/app"; import { getAuth } from "firebase/auth"; import { getFirestore } from "firebase/firestore"; import { getAnalytics } from "firebase/analytics"; const firebaseConfig = {...}; const app = initializeApp(firebaseConfig) const analytics = getAnalytics(app); const auth = getAuth(app); const db = getFirestore(app); export { auth, db, };

No necesita verificar si Firebase ya se ha inicializado cuando usa Modular SDK.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!