Is The Firebase Js Sdk Package Compatible With The Node.js Environment Of A Cloud Function? Why Use Firebase-admin?
Solution 1:
You can use firebase
in a Node.js environment to access certain services. However, those service calls will be made as if they were made by an end-user. Meaning all the security rules, per-user request quotas and abuse prevention mechanisms in the Firebase backend servers come into play. If your rules only allow authenticated users to access Firestore, then you will have to authenticate as an end-user in the server prior to calling Firestore. Each invocation of the cloud function will have to do this since functions do not keep state. Running that many authentication attempts from the same IP block is likely to eventually trigger some abuse prevention safeguard, and result in errors.
As a rule of thumb, use the client SDK for client-side apps, and use the server/Admin SDK for server-side applications. There are times when you might want to bend this rule. But that should be the exception as opposed to the norm, and should be done only after careful consideration.
Solution 2:
In theory, could I use the firebase package to call firebase services from the Node.js environment of a cloud function?
The Firestore web SDK provided by Firebase was not meant for use in nodejs environments. If it happens to work, then I would consider that a bonus. But I would not expect that at all, and I would definitely not depend on that.
is there a reason why I should prefer using the firebase-admin instead of the firebase JS SDK package?
The main reason is because firebase-admin specifically supports nodejs. That's how it was meant to work. The Admin SDK is just a wrapper around the Firestore SDK provided by Google Cloud. Once you have Firestore object, it's exactly the same stuff.
As I mentioned in your other question, the SDKs might appear similar, but they are not the same. They don't have the same features and APIs.
Post a Comment for "Is The Firebase Js Sdk Package Compatible With The Node.js Environment Of A Cloud Function? Why Use Firebase-admin?"