dimanche 1 octobre 2017

snapshot.val() returns null using firebase once when database is not null and reference path is correct [on hold]

Database data

"Users" :   
{  
    "MmLnJGYHioOeAfIaYcj1IVdlTYY2" :   
    {  
        "Events Statuses" :   
            {  
                "-KuyrFfM2oa8SQhLCdxY" :   
                    {
                         "status" : true  
                    }  
            },    
      "email" : "dummy@gmail.com",    
      "name" : "dummy name",    
      "password" : "qwerty"    
    }    
}    

I tried following the firebase docs and used exact syntax but don't understand why I'm not getting value from database because I have used the exact code to get the same value in other pages of my web app, please help.

//database ref

var Database = firebase.database().ref();

//fetch and store user key
var user_key;

firebase.auth().onAuthStateChanged( 
  function(user) 
  {
    if (user) 
    {
      // User is signed in.
      user_key = user.uid;
      // console.log(user);
      // ...
    } 
    else 
    {
      // User is signed out.
      // ...
    }
  }
);

//store event key

var event_key = location.search.substring(1).split('=')[1];

  Database.child("Users/" + user_key + "/Events Statuses/"+ event_key + "/").once("value")
  .then(
    function (snapshot)
      {
  //snapshot .val() is null here 
        console.log(snapshot.key);
        console.log(snapshot.val());
      }
   );

Console Output:

-KuyrFfM2oa8SQhLCdxY
null




Aucun commentaire:

Enregistrer un commentaire