Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

325
Vistas
Client is Offline error while using firebase realtime database

I am trying to make a small database system for my client that will capture his website's registered users name and there spent amount. Based on there spent amount he will get some gifts. Using firebase realtime database i am able to store user spent amount but when i try to get data from database. I am getting the following Error from the line: get(child(userDbRef, "User-ID-"+userID)):

"Uncaught (in promise) Error: Error: Client is offline."

initailData(); will work if user does not have data stored already and if the data has been stored once then runInitialFunction(); will work and get/retrieve data from database.

Here is my code

  // Import the functions you need from the SDKs you need
  import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-app.js";
  // TODO: Add SDKs for Firebase products that you want to use
  // https://firebase.google.com/docs/web/setup#available-libraries

  // Your web app's Firebase configuration
  const firebaseConfig = {
    apiKey: "AIzaSyAfA1HIkamXEFtDidPkpxaltDVsWpFWepE",
    authDomain: "thundersmmpanel-77fb2.firebaseapp.com",
    databaseURL: "https://thundersmmpanel-77fb2-default-rtdb.firebaseio.com",
    projectId: "thundersmmpanel-77fb2",
    storageBucket: "thundersmmpanel-77fb2.appspot.com",
    messagingSenderId: "867306490186",
    appId: "1:867306490186:web:93407cb6d8b0e9abe9d9b3"
  };

  // Initialize Firebase
  const app = initializeApp(firebaseConfig);

  
  //<!--my code-->
  import {getDatabase, ref, set, get, child, update}
  from "https://www.gstatic.com/firebasejs/9.6.0/firebase-database.js";
  
  const userID = {{user['id']}};
  const userName = "{{user['username']}}";
  const pointsDb = getDatabase();
  
  //<!-- initial data -->
  function initailData() {
    set(ref(pointsDb, "User-ID-"+userID),{
        UserName: userName,
        InitialSpent: {{user['spent']}},
        ThisRun: 1
    })
    .then(function(){
        alert("Done");
    })
    .catch(function(error){
        alert("Error "+error);
    });
    console.log("initailData");
  }
  
  
  function runInitialFunction() {
    const userDbRef = ref(pointsDb)
    get(child(userDbRef, "User-ID-"+userID)).then((snapshot)=>{
        if(snapshot.exists()){
            
        }else{
            initailData();
        }
    });
    console.log("runInitialFunction");
  }
  runInitialFunction();
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda