英文:
Node JS - Initialize Firebase using service account key or Firebase config file?
问题
我试着学习如何在Node.js中使用Firebase,但有一点我无法理解。我已经寻找了几天的解释,但就是找不到有用的信息。
在按照一些教程的步骤后,我感到困惑,因为其中一些使用了serviceAccountKey
文件,看起来像这样:
"type": "service_account",
"project_id":
"private_key_id":
"private_key":
"client_id":
"auth_uri":
"token_uri":
"auth_provider_x509_cert_url":
"client_x509_cert_url":
然后他们这样初始化它:
admin.initializeApp({
credential: admin.credential.cert(credentials)
});
而其他人使用了在Firebase注册应用程序时生成的Firebase配置文件,它看起来像这样:
const firebaseConfig = {
apiKey:
authDomain:
projectId:
storageBucket:
messagingSenderId:
appId:
measurementId:
}
这两种方式有什么区别?何时应该使用第一种方式或第二种方式?
如果有相关的文档,请帮我查找,因为我找不到相关信息。
英文:
I'm trying to learn how to use Firebase with Node JS and there's a thing I can't understand. I've been looking for an explanation for a few days now, but I just can't find something useful.
After following some tutorials, I'm confused because some of them use the serviceAccountKey file which looks like
"type": "service_account",
"project_id":
"private_key_id":
"private_key":
"client_id":
"auth_uri":
"token_uri":
"auth_provider_x509_cert_url":
"client_x509_cert_url":
and then they initialize it like this
admin.initializeApp({
credential: admin.credential.cert(credentials)
});
While others use the Firebase configuration file which is generated when you register the app on Firebase, which looks like this:
const firebaseConfig = {
apiKey:
authDomain:
projectId:
storageBucket:
messagingSenderId:
appId:
measurementId:
}
What is the difference? When are you supposed to use the first way or the second way?
If there is some documentation about this, please help me with it because I can't find anything relevant.
答案1
得分: 0
第一个提到的是用于后端的/Admin SDK代码。
第二个是用于前端的/web SDK。
这些SDK不兼容,并且需要不同的初始化方法。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论