首页 > firebase > firebase与firebase-functions和firebase-admin的区别是什么?

firebase与firebase-functions和firebase-admin的区别是什么? (What is the difference of firestore from firebase-functions and firebase-admin?)

问题

我正在使用云功能处理我的应用程序的敏感任务,我已经看到文档接近它使用firestore,或者生活在

import * as functions from 'firebase-functions'
const { firestore } = functions

要么

import * as admin from 'firebase-admin'
admin.initializeApp()
const { firestore } = admin

我的直觉说,如果我使用管理员,我可以绕过所有安全规则,即从我的firestoe中的任何地方读取和接收更新,与写入相同。所以我似乎可以在任何地方使用来自管理员的firestore,它firebase-functions只是具有管理员权限的一个?

它是否正确?如果不是有什么区别?

我的项目可以使用firebase-admin吗?

解决方法

firestore-functions模块仅用于部署到Cloud Functions的代码。它在该环境之外没有任何用处。

firebase-admin SDK用于在您控制的后端服务器上访问Firebase产品,可以是云功能,甚至是桌面。它通常具有对所有内容的完全访问权限,具体取决于您用于初始化它的服务帐户。

问题

I'm using cloud functions to handle sensitive tasks of my app, I've seen documentation approaching it with using firestore that either lives on

import * as functions from 'firebase-functions'
const { firestore } = functions

or

import * as admin from 'firebase-admin'
admin.initializeApp()
const { firestore } = admin

My instinct says that if I use admin one I can bypass all security rules i.e read from and receive updates from any place in my firestoe, same with writes. So it seems that I can use firestore from admin everywhere, its identical to one from firebase-functions just has admin privileges?

Is this correct? If not what is the difference?

Can my project just use firebase-admin?

解决方法

The firestore-functions module is only for use with code deployed to Cloud Functions. It doesn't do anything useful outside of that environment.

The firebase-admin SDK is for accessing your Firebase products on a backend server you control, which could be Cloud Functions, or even your desktop. It will typically have full access to everything, as determined by the service account you used to initialize it.

相似信息