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

228
Views
firebase js sdk query snapshot return null or error

Using firebase sdk I successfully login a user but later I can't query any data from the realtime database. Chrome console says that snapshot.val() is null or it fires an error in firebase-database.min.js. I tried many sort of querys and path format in ref value (from official doc and forums). When I try to console.log the snapshot, it returns a firebase object. Adding .val() returns null. But I have data on db.

I have also tried .once or await async functions but it gives me same result.

I use firebase js sdk from cdn (v8): https://cdnjs.com/libraries/firebase/8.10.0

Links to code and errors screnshots: removed

Link to lite version project: removed

Firebase injection and init:

<!-- index.html -->

<script src="../lib/jquery_360/jquery360.min.js"></script>
<script src="../lib/bootstrap_5/js/bootstrap.bundle.min.js"></script>

<!-- <script src="../lib/firebase/firebase.min.js"></script> -->
<script src="../lib/firebase/firebase-app.min.js"></script> 
<script src="../lib/firebase/firebase-auth.min.js"></script>
<script src="../lib/firebase/firebase-database.min.js"></script>    

<script src="../script/modal.js"></script>
<script src="../script/utility.js"></script>

<script src="../script/customer.js"></script>

<title>customer</title>

// index.js - jquery onload function

const firebaseApp = firebase.initializeApp({
    // keys here...
});

auth = firebase.auth(); 
db = firebase.database(); 

firebase.auth().onAuthStateChanged((user) => {
    if (user) {
        var uid = user.uid;
        console.log('user logged in!');     
        
        $('#login_popup').modal('hide');
        Clear_Popup_Message('login_popup_msg_box', null); 
    
        GetAllData();         
    } else {
        console.log('user not logged in!');
    }
  });

// GetAllData()

db.ref('menus').orderByChild('list_order').on('value', (snapshot) => {
            prj.configs.menu = snapshot.val();  
});

firebase realtime db

query error

rules

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

0

I'm not sure what is wrong with the libraries on Cloud Flare, but if I change your imports from

<script src="https://cdnjs.cloudflare.com/ajax/libs/firebase/8.10.0/firebase-app.min.js" integrity="sha512-XNRpfd3CxEDrXcXWvht51k3l8G5cZhcY0kehFjUohBhgRDCozbdSaGz3w96WlDxAgiNZndKnpn1+4532FS3p3w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/firebase/8.10.0/firebase-auth.min.js" integrity="sha512-GAEvFso2oksY5JFkHlrfLhZgAV6aL48qxnbxPnbKnNLeG/XsU/c0lh/g9gocZ2RtbRx6VDTqspPEy9ixWvbfzw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/firebase/8.10.0/firebase-database.min.js" integrity="sha512-XDKFSZOhFNmwmx69Xr0j3zmePQ3NoSgpzZPr49P6oV7ME5ZhEXUqu+KUA0vQtof87P6IX+ycg4PmSms/EF8/pw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

To

<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-database.js"></script>

Everything suddenly works without errors.

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!