I noticed that Firebase has changed recently. I'm building a node.js app that requires firebase and previously this was enough:
var Firebase = require("firebase");
var firebaseRef = new Firebase("https://blabla.firebaseio.com/");
According to 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 app. That 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 I run my node.js application, I receive 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 F.u (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.
It's not obvious from the docs but for server-side use of Firebase, you need to authenticate with a "service account" which means creating some credentials, downloading them and initialising the firebase library differently than you would in a browser.
If you are migrating a Node.js app, you will now need to authenticate with a service account. See the server SDK docs for full instructions.
More detail in the docs here: https://firebase.google.com/docs/server/setup#add_firebase_to_your_app
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With