Issues building SSA plugin with Firebase

Hi bubblers

I am building a plugin using Firebase. I was able to build element actions that signed users in and called their data. Works perfect!

Now I am trying to implement the admin SDK

I am able to initialize the Firebase admin project. But that’s where it stops. I can’t call to the database and receive data. I’m using a very similar method to the client side JavaScript sdk

i expect:
app initializes firebase if admin.apps.length doesnt exist. this part works no problem
next
i want to call out to ‘test’ and get all documents held within that collection

the following parts dont happen

i would then do work with them and eventually call return_data()

then return_data() would expose the state “data”

Here is the code I am using.

    function(properties, context) {
var serviceAccount = {'jsonObjectFromFirebase'};
var list =[];

var admin = require("firebase-admin");


// 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) => {
    snapshot.val().forEach(element => {
        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: "https://thunkableproject-f51d9-default-rtdb.firebaseio.com"
});
}
}

@jared.gibb Did you get this resolved?

I have been able to implement this using a server side action in the firebase admin SDK. I am able to return all of my data as an array of objects and use that the same as any other data source.

The next target to taco will be using just the author and database SDKs and not the admin SDK. Also using them as a client side action and not a server side action.

Did you have a particular question about anything?