flamelink / flamelink-js-sdk

🦊 Official Flamelink JavaScript SDK for both the Firebase Realtime database and Cloud Firestore
https://flamelink.github.io/flamelink-js-sdk
MIT License
43 stars 5 forks source link

Populate not returning image #175

Open petermenocal opened 2 years ago

petermenocal commented 2 years ago

Populate is not working as expected on 1.0.0-alpha.34 I have a simple image field in my schema. when I set populate: true or populate: ["image"] on either app.content.get()or app.content.getByField() I return no results. If I remove populate: true and all variations, the proper result is returned.

petermenocal commented 2 years ago

I finally got an error. It seems the sdk thinks firebase-admin is client-side still even though it is not:

[Error [FlamelinkError]: 

The Firebase client-side SDK cannot access the Storage Bucket server-side.
Please use the admin SDK instead - https://www.npmjs.com/package/firebase-admin

Instructions here: https://flamelink.github.io/flamelink-js-sdk/#/getting-started?id=usage

] {
  code: 'service-unavailable',
  showStackTrace: false
}

relevant code from file:

var express = require("express");
var router = express.Router();
var firebaseApp = require("firebase-admin");
var flamelink = require("flamelink");

var serviceAccount = require("../firebase-adminsdk.json");

firebaseApp.initializeApp({
  credential: firebaseApp.credential.cert(serviceAccount),
  databaseURL: "...",
  storageBucket: "...",
});

const app = flamelink({
  firebaseApp, 
  dbType: "rtdb", 
});

router.post("/", function (req, res, next) {
  app.content
    .get({
      schemaKey: "product",
      populate: ["image"],
    })
    .then((x) => console.log(x))
    .catch((e) => console.log(e));
  res.send(200);
});

module.exports = router;
gitdubz commented 2 years ago

Hi @petermenocal, which version of the Firebase admin SDK are you using?

petermenocal commented 2 years ago

1.0.0-alpha.34

gitdubz commented 2 years ago

Thanks that looks like the Flamelink SDK version, but would like to see if it is related to the Firebase SDK version (not the Flamelink SDK)

gitdubz commented 2 years ago

Could you potentially try the following for me please

replace

var flamelink = require("flamelink");

with

var flamelink = require("flamelink/app");
require("flamelink/content");
require("flamelink/storage");