Firebase "throw new Error (" Invalid service account "); error message

I noticed that Firebase has recently changed. I am creating a node.js application that requires firebase, and previously this was enough:

var Firebase = require("firebase"); var firebaseRef = new Firebase("https://blabla.firebaseio.com/"); 

This link: https://firebase.google.com/docs/web/setup#prerequisites

you need to create a firebase project in the new firebase console and then add firebase to your web application. This gives you something similar to:

 // Initialize Firebase var config = { apiKey: '<your-api-key>', authDomain: '<your-auth-domain>', databaseURL: '<your-database-url>', storageBucket: '<your-storage-bucket>' }; firebase.initializeApp(config); 

However, when starting my node.js application, I get the following error message:

 throw new Error('Invalid service account provided'); ^ Error: Invalid service account provided at new Auth (C:\Projects\lambdaTestFunction\node_modules\firebase\auth-node\auth.js:61:11) at Object.serviceFactory [as auth] (C:\Projects\lambdaTestFunction\node_modules\firebase\auth-node\index.js:14:14) at Fu (C:\Projects\lambdaTestFunction\node_modules\firebase\app-node.js:14:94) at C:\Projects\lambdaTestFunction\node_modules\firebase\auth-node\index.js:31:9 at C:\Projects\lambdaTestFunction\node_modules\firebase\app-node.js:11:272 at Array.forEach (native) at Object.e.initializeApp (C:\Projects\lambdaTestFunction\node_modules\firebase\app-node.js:11:245) at Object.<anonymous> (C:\Projects\lambdaTestFunction\index.js:44:10) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) 

What exactly am I missing?

Thanks in advance.

+8
javascript firebase
source share
2 answers

This is not obvious from the documents, but in order to use Firebase on the server side, you need to authenticate with a “service account”, which means creating some credentials, loading them and initializing the firebase library in a different way than in the browser.

If you are porting the Node.js application, you now need to authenticate with the service account. For detailed instructions, see the server SDK docs.

More details in the docs: https://firebase.google.com/docs/server/setup#add_firebase_to_your_app

+18
source share

I use Firebase with Electron, it seems that for electronic applications you also need service accounts.

0
source share

All Articles