adding guard for other components already initalized firebase-admin
This commit is contained in:
@ -15,36 +15,32 @@ module.exports = function(RED) {
|
|||||||
//------------------------------
|
//------------------------------
|
||||||
this.admin = _admin
|
this.admin = _admin
|
||||||
this.storage = s
|
this.storage = s
|
||||||
if(!init){
|
let global = this.context().global
|
||||||
|
if(!init)
|
||||||
|
{
|
||||||
console.log('setting admin....')
|
console.log('setting admin....')
|
||||||
this.credentials = JSON.parse(this.cred);
|
this.credentials = JSON.parse(this.cred);
|
||||||
let credobj = _admin.credential.cert(this.credentials)
|
let credobj = _admin.credential.cert(this.credentials)
|
||||||
//console.dir(credobj)
|
//console.dir(credobj)
|
||||||
//process.env.GOOGLE_APPLICATION_CREDENTIALS = 'creds.json'
|
//process.env.GOOGLE_APPLICATION_CREDENTIALS = 'creds.json'
|
||||||
init = true
|
init = true
|
||||||
|
|
||||||
console.log('*** parsed firebase credentials: '+this.credentials.type+', project-id: '+this.credentials.project_id)
|
console.log('*** parsed firebase credentials: ' + this.credentials.type + ', project-id: ' + this.credentials.project_id)
|
||||||
_admin.initializeApp({
|
_admin.initializeApp({
|
||||||
credential: credobj,
|
credential: credobj, databaseURL: this.dburl
|
||||||
databaseURL: this.dburl
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let global = this.context().global
|
|
||||||
|
|
||||||
global.set('firebase', _admin)
|
global.set('firebase', _admin)
|
||||||
console.log('********************************************************** setting storage....')
|
|
||||||
|
|
||||||
s = new Storage({
|
|
||||||
//projectId: 'something-2e584',
|
|
||||||
//email: 'firebase-adminsdk-d1xiy@something-2e584.iam.gserviceaccount.com',
|
|
||||||
credentials: this.credentials
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
global.set('cloud-storage', s)
|
|
||||||
|
|
||||||
//s = new Storage()
|
|
||||||
}
|
}
|
||||||
|
console.log('********************************************************** setting storage....')
|
||||||
|
s = new Storage({
|
||||||
|
//projectId: 'something-2e584',
|
||||||
|
//email: 'firebase-adminsdk-d1xiy@something-2e584.iam.gserviceaccount.com',
|
||||||
|
credentials: this.credentials
|
||||||
|
})
|
||||||
|
global.set('cloud-storage', s)
|
||||||
|
|
||||||
|
//s = new Storage()
|
||||||
|
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("firebase-config", FirebaseConfigNode);
|
RED.nodes.registerType("firebase-config", FirebaseConfigNode);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-contrib-firebase-admin",
|
"name": "node-red-contrib-firebase-admin",
|
||||||
"version": "1.1.12",
|
"version": "1.1.13",
|
||||||
"description": "A node-red module that wraps the server-side admin SDK of firebase, firestore, et.c.",
|
"description": "A node-red module that wraps the server-side admin SDK of firebase, firestore, et.c.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user