Firebase“抛出新的错误(”提供的服务帐号无效“);错误信息 [英] Firebase "throw new Error('Invalid service account provided');" error message
问题描述
var Firebase = require(firebase );
var firebaseRef =新的Firebase(https://blabla.firebaseio.com/);
根据以下链接: https://firebase.google.com/docs/web/setup#prerequisites
您需要创建一个Firebase在新的Firebase控制台中添加项目,然后将Firebase添加到您的Web应用程序。这给了你类似的东西:
//初始化Firebase
var config = {
apiKey:' < your-api-key>',
authDomain:'< your-auth-domain>',
databaseURL:'< your-database-url>',
storageBucket: '< your-storage-bucket>'
};
firebase.initializeApp(config);
但是,当我运行我的node.js应用程序时,收到以下错误消息:
抛出错误('Invalid service account provided');
^
错误:无效的服务帐户在新的Auth提供
(C:\Projects\lambdaTestFunction\\\
ode_modules\firebase\auth-node\auth。 js:61:11)
在Object.serviceFactory [as auth](C:\Projects\lambdaTestFunction\\\
ode_modules\firebase\auth-node\index.js:14:14)$ b (C:\Projects\LmbdaTestFunction\\\
ode_modules\firebase\app-node.js:14:94)
在C:\Projects\lambdaTestFunction\\\
ode_modules\firebase \auth-node\index.js:31:9
在C:\Projects\lambdaTestFunction\\\
ode_modules\firebase\app-node.js:11:272
在Array .forEach(native)
在Object.e.initializeApp(C:\Projects\lambdaTestFunction\\\
ode_modules\firebase\app-node.js:11:245)
在Object。< ;匿名> (C:\Projects\LmbdaTestFunction\index.js:44:10)
在Module._compile(module.js:409:26)
在Object.Module._extensions..js( module.js:416:10)
我错过了什么?
在此先感谢。
从文档不是很明显,但对于服务器端使用Firebase,您需要使用服务帐户进行身份验证,这意味着创建一些凭据,下载这些凭据并以不同于浏览器的方式初始化Firebase库。
如果您要迁移Node.js应用程序,则需要使用服务帐户验证
。
文档中有更多详细信息:
https://firebase.google.com/docs/server/setup#add_firebase_to_your_app
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
这篇关于Firebase“抛出新的错误(”提供的服务帐号无效“);错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!