Search code examples
firebasegoogle-cloud-platformgoogle-cloud-firestorefirebase-authenticationgoogle-iam

Can I use a service account to authenticate/authorize my firebase web sdk?


I am trying to use the client sdk server side, since I prefer the client sdk's approach in writing. i.e. using (ref, setDoc, updateDoc, useTransaction), and also because according to this thread, it is totally fine: Firestore on the server side

When using the firebase admin sdk, we could authorize it by using service account credentials.

const adminApp = admin.initializeApp({
  credential: admin.credential.applicationDefault(), 
  projectId: process.env.FIREBASE_PROJECT_ID,
})

I'm wondering if we could do the same with the client sdk. something like:

import { initializeApp } from 'firebase/app'

const app = initializeApp(
  firebaseConfig, 
  // use service account credentials here ? 
  )

export const firestoreDb = getFirestore(app)

thanks in advance for any answers, suggestions, tips, or advices!


Solution

  • This is not possible. If you want to work with Firestore on a backend, you should use the backend SDKs that accept service accounts, not the frontend SDKs which only accept client configuration objects.

    If you want to investigate this further, look at the API documentation for the web client SDK initializeApp and see that there are no options for service account credentials.