我注意到 Firebase 最近发生了变化。我正在构建一个需要 firebase 的 node.js 应用程序,以前这就足够了:
var Firebase = require("firebase");
var firebaseRef = new Firebase("https://blabla.firebaseio.com/");
根据此链接:https://firebase.google.com/docs/web/setup#prerequisites
您需要在新的 firebase 控制台中创建一个 firebase 项目,然后将 firebase 添加到您的网络应用程序中。这给你类似的东西:
// Initialize Firebase
var config = {
apiKey: '<your-api-key>',
authDomain: '<your-auth-domain>',
databaseURL: '<your-database-url>',
storageBucket: '<your-storage-bucket>'
};
firebase.initializeApp(config);
但是,当我运行我的 node.js 应用程序时,我收到以下错误消息:
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)
我到底错过了什么?
提前致谢。
最佳答案
从文档中看并不明显,但对于 Firebase 的服务器端使用,您需要使用“服务帐户”进行身份验证,这意味着创建一些凭据、下载它们并以不同于在浏览器中的方式初始化 firebase 库。
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.
此处文档中有更多详细信息: https://firebase.google.com/docs/server/setup#add_firebase_to_your_app
关于javascript - Firebase "throw new Error(' 提供的服务帐户无效');"错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37424594/