title: Why does firebase return null when using admin
body: <p>I am using the firebase admin sdk with bubble as a nodejs project</p>
  <p>here is the code i am trying.  THIS doesn't work. I have included updated code at the bottom but will leave this for now hoping others can learn from my errors.</p>
  <pre><code>function(properties, context) {
      console.log('trying')
      var list = []
      var util = require(&quot;util&quot;)
  
      var admin = require('firebase-admin');
  
      var serviceAccount = &lt;COPIED/PASTED FROM FIREBASE&gt;
  
      // Fetch the service account key JSON file contenT
  
  
      if (admin != null) {
          admin.initializeApp({
              credential: admin.credential.cert(serviceAccount),
              databaseURL: &quot;https://login-database-brc.firebaseio.com&quot;
  
          })
          list.push('logged into app')
          var db = admin.database();
          var ref = db.ref('BRC/4jV39aEK6jOecLdKONJMKatsEYn1/data')
  
  
          ref.once('value').then((snapshot) =&gt; {
              snapshot.val().forEach(element =&gt; {
                  list.push('check')
                  list.push(element.Name)
  
              })
  
  
          });
      } else {
          list.push('nothing happened')
      }
  
  
  
      // As an admin, the app has access to read and write all data, regardless of Security Rules
  
  
  
      return {
          data: list
      }
  
  }
  </code></pre>
  <p>here are the rules</p>
  <pre><code>{
      &quot;rules&quot;:{
        &quot;BRC&quot;: {
          &quot;$uid&quot;:{ 
              &quot;.read&quot;: &quot;$uid === auth.uid&quot;,
              &quot;.write&quot;: &quot;$uid === auth.uid&quot;
          }
      }
  }
  }
  </code></pre>
  <p>I only end up seeing 'logged in' in the output list. I would expect to see the name property from each object in the data bucket.</p>
  <p>I am able to make this work fine client side using the standard sdk, and using password authentication. I can’t seem to get beyond initializing the apps Firebase instance.</p>
  <p>i do have /BRC with rules that require authentication, but with the server SDK i didnt think this mattered</p>
  <p>I want to access all ojects held within BRC/4jV39aEK6jOecLdKONJMKatsEYn1/data</p>
  <p>[UPDATED CODE TO PERFORM OPERATIONS SYNCRONOUS]</p>
  <pre class="lang-js prettyprint-override"><code>function(properties, context) {
  var serviceAccount = {'jsonObjectFromFirebase'};
  var list =[];
  
  var admin = require(&quot;firebase-admin&quot;);
  
  
  // Initialize the app with a service account, granting admin privileges
  if (!admin.apps.length){
      initializeApp(serviceAccount)
  };
  
  // As an admin, the app has access to read and write all data, regardless of Security Rules
      
  admin.database().ref('test').once('value')
      .then((snapshot) =&gt; {
      snapshot.val().forEach(element =&gt; {
          let a = element.name;
          list.push(a);
       })
      
      return_data(list)
      
  });
      
  function return_data (list){
      return { data: list};
  };
      
  function initializeApp (serviceAccount){
      admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: &quot;https://thunkableproject-f51d9-default-rtdb.firebaseio.com&quot;
  });
  }
  
  
  }
  </code></pre>
  <p>the issue is that now return_data is never called. so I'm not sure what's happening here.</p>
  <p>[update 2, trying again to create a synchronous call</p>
  <pre><code>
  var list =[]
  
  var admin = require(&quot;firebase-admin&quot;);
  
  
  // Initialize the app with a service account, granting admin privileges
  if (!admin.apps.length){
      initializeApp(serviceAccount)
  }
  
  // As an admin, the app has access to read and write all data, regardless of Security Rules
      
  admin.database().ref('BRC/4jV39aEK6jOecLdKONJMKatsEYn1/data').once(&quot;value&quot;, function(snapshot){
      let element = snapshot.val()
      let list = []
      for (var key in element) {
         list.push(element[key].Name) 
      }
      
      return_data(list)
    })
  
      
  function return_data (list){
      return { data: list}
  }
      
  function initializeApp (serviceAccount){
      admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: &quot;https://login-database-brc.firebaseio.com&quot;
  });
  }
  
  </code></pre>
  <p>I have also tried this to no avail</p>
  <pre><code>    
  var promise = admin.database().ref('BRC/4jV39aEK6jOecLdKONJMKatsEYn1/data').once(&quot;value&quot;);
      
  promise.then(snapshot =&gt; {
      let element = snapshot.val()
      let list = []
      for (var key in element) {
         list.push(element[key].name) 
      };})
  .catch(error =&gt; {
      alert(error)
  });
      
  return { data: list}
  </code></pre>
  <hr />
  <h2>Update 9:23 EST 12/29/20</h2>
  <p>I think I now am calling this function in an asynchronous way that should wait for a callback. the issue now is that the code in the .then() never executes.</p>
  <pre><code>
  function getData() {
     var promise = admin.database().ref('BRC/4jV39aEK6jOecLdKONJMKatsEYn1/data').once(&quot;value&quot;);
  
     promise.then(snapshot =&gt; {
        let element = snapshot.val()
        let list = []
        for (var key in element) {
           list.push(element[key].Name)
        };
        return list;
     })
        .catch(error =&gt; {
           return error
        });
  
     return promise;
  }
  
  
  
  
  getData().then((list) =&gt; {
     return { &quot;data&quot;: list }
  })
  </code></pre>