Closed ribalnasr closed 4 years ago
Hi @ribalnasr
Does this work if you run it server-side as opposed to a cloud function?
I will have a look at it and see if I can reproduce it within a cloud function.
i haven't tried that. i usually only work server-side within a firebase project. i will try to reproduce it with node as soon as i can. meanwhile awaiting your reply
On Wed, Jul 22, 2020 at 4:07 PM De Wet van der Merwe < notifications@github.com> wrote:
Hi @ribalnasr https://github.com/ribalnasr
Does this work if you run it server-side as opposed to a cloud function?
I will have a look at it and see if I can reproduce it within a cloud function.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/flamelink/flamelink-js-sdk/issues/136#issuecomment-662441722, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGFEVDOEM7H2LY77SR77N7TR43P7NANCNFSM4PEVV6OA .
i just tried outside firebase and it's working! any updates from your side?
I use Flamelink in Firebase Cloud Functions and don't have any issues. I noticed that in my setup, I'm importing Flamelink like this, vs what you shared (however this could just be a difference in typescript settings)
// How my app is set up
import * as flamelink from "flamelink/app";
// your example
import flamelink from 'flamelink/app';
You also may need to get your admin app using the admin.app()
function, rather than the return of admin.initializeApp
- at least that's how my code has been running for months. See below.
import * as admin from "firebase-admin";
admin.initializeApp();
const firebaseApp = admin.app();
// then initialize flamelink like you had
Thanks @Neilpoulin I think that is exactly the issue.
Might be good to add an example on the docs for this. @ribalnasr to summarize
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as flamelink from 'flamelink/app';
import 'flamelink/content';
admin.initializeApp();
const firebaseApp = admin.app();
const flApp = flamelink({
firebaseApp,
dbType: 'cf',
env: 'production',
locale: 'en-US',
});
export const testFunction = functions.https.onRequest((request, response) => {
....
});
Unfortunately this still doesn't work.
here are my packages versions:
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.1",
"flamelink": "^1.0.0-alpha.31",
and firebase-tools is version 8.6.0
what are yours?
I finally got it working!
I was emulating the firebase project using firebase emulators:start
This was emulating a local/empty version of Firestore hence flamelink.content.get() was returning empty values!!!
It worked when I ran firebase emulators:start --only functions
.
Another important thing to note: i tried to use the same logic for flamelink.storage.getUrl(...)
but got SigningError. This was fixed when explicitly adding the service account to firebase admin as follows:
const serviceAccount = require("./path/to/service-account.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: '...',
storageBucket: '...'
});
Thanks, we will add a section to the docs for this 👍
I've been trying to get flamelink to work in a firebase function with no success. the result has no error but returns undefined, here's my code:
Help please.. been stuck on this for days.