Reputation: 2972
I have a cloud function that translates text using google translate api. It utilizes this piece of code:
const functions = require('firebase-functions');
function createTranslateUrl(lang, text) {
return `https://www.googleapis.com/language/translate/v2?key=${functions.config().firebase.apiKey}&source=en&target=${lang}&q=${text}`;
}
The problem is in functions.config().firebase.apiKey
part. For some time it worked fine but suddenly it started to return undefined
.
Here's how the config looks like now:
config { firebase:
{ projectId: 'projectname',
databaseURL: 'https://projectname.firebaseio.com',
storageBucket: 'projectname.appspot.com',
credential: ApplicationDefaultCredential { credential_: MetadataServiceCredential {} } } }
I hardcoded the apiKey copying it from firebase console and it works fine for now.
My questions are is it safe to use hardcoded api key? And what might cause functions.config().firebase.apiKey
to return undefined?
Upvotes: 0
Views: 2108
Reputation: 75
firebase.apiKey
was dropped from functions.config()
See also this issue on github https://github.com/firebase/firebase-functions/issues/196
Upvotes: 1
Reputation: 228
Any luck with this? I'm having exact same issue where functions.config().firebase.apiKey
is returning undefined
.
This started happening after my deployment yesterday. I did check firebase release notes but nothing related to config there.
UPDATE: It turns out there we were using old version of firebase-functions
. Upgrading to latest version (0.9.1
) fixed issues.
Upvotes: 0