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

205
Views
La base de datos en tiempo real de firebase no funciona como se esperaba

Soy un desarrollador junior, así que sean fáciles conmigo.

Mi objetivo es autenticar a un usuario de forma anónima cuando abre la página de inicio, luego, si todo salió bien, obtiene los datos de la base de datos en tiempo real, ¡pero solo si la coincidencia de uid está bien!

He ahí mis reglas:

 { "rules": { "$uid": { ".read": "auth != null && auth.uid == $uid", ".write": "false", } } }

Mi base de datos está estructurada así https://ibb.co/jkRBCsF


El inicio de sesión anónimo está en el contexto.

 export const AuthContextProvider = ({ children }: Props) => { React.useEffect(() => { signInAnonymously(auth) .then(() => { // Signed in.. }) .catch((error) => { const errorCode = error.code; const errorMessage = error.message; // ... }); }, []); const values = {}; return <AuthContext.Provider value={values}>{children}</AuthContext.Provider>; };

Luego, cuando abro una página, por ejemplo, '/crew', getStaticProps inicia fetchPlanetInfo

 export const getStaticProps: GetStaticProps = async () => { const planetInfo = await fetchPlanetsInfo("destinations"); return { props: { data: planetInfo, }, }; };
 export function fetchPlanetsInfo(query: string) { let dataArr: any = []; try { onAuthStateChanged(auth, (user) => { if (user) { const uid = user.uid; const databaseCall = ref(db, uid + "/" + query); onValue(databaseCall, (snapshot) => { const data = snapshot.val(); dataArr.push(data); }); } else { console.log("user is signout"); // User is signed out // ... } }); } catch (error) { console.log(error); } return dataArr.flat(); }

Intenté averiguar dónde está el error pero no encontré la solución.

Mi problema es que los datos no se obtienen de la base de datos. fetchPlanetsInfo devuelve nulo. Creo que mis reglas están mal escritas.

about 4 years ago · Juan Pablo Isaza
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!