Previously, all of my firestore query are using v8 namespaced.
All transactions are having full privileges using Firebase Admin SDK on my server.
I want to update the v8 namespaced to v9 modular syntax:
// from this
db.collection("cities").where("capital", "==", true).get();
// to this
const q = query(collection(db, "cities"), where("capital", "==", true));
Using Firebase Client SDK v9, it works when I force the Database Rules to true
, without doing so I got error permission-denied
.
import { initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';
const firebasev9 = initializeApp(configv9);
const db = getFirestore(firebasev9);
const q = query(collection(db, "cities"), where("capital", "==", true));
Firebase Admin SDK v10 now have modular export similar as client sdk, so I tried it:
import { initializeApp } from 'firebase-admin/app';
import { getFirestore } from 'firebase-admin/firestore';
const firebaseAdminv9 = initializeApp(configAdminv9);
const db = getFirestore(firebaseAdminv9);
const q = query(collection(db, "cities"), where("capital", "==", true));
Now the error is Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore
.
Seems like we cannot use the instance of getFirestore
from firebase-admin
.
Is there any way for the client sdk to have admin privilege?
No, it is not possible. The client SDK cannot be initialized with a service account, which is the thing that's required for privileged access that bypasses security rules. The client SDK only passes along the currently signed in user from Firebase Auth for authorization.
Furthermore, it is not possible at all mix usage of the client and admin SDKs. Even though they have APIs that look similar, they are just not compatible with each other at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With