-
Notifications
You must be signed in to change notification settings - Fork 408
Closed
Description
There is a related issue (#575) but it seems that it's still unresolved.
We would like to connect the admin SDK to firebase emulators when running tests. Our setup code looks like this:
import * as admin from 'firebase-admin'
admin.initializeApp({ credential: ... })
export default admin
Then in every file that needs access to firestore, we use:
import firebase from `./firebase`
firebase.firestore().doSomething()
How can we modify this setup so that is connects to the firebase emulators instead?
This is what we've tried so far:
- Have the setup code return the
@firebase/testingnamespace depending on the node environment. However this library doesn't setup a default firebase app so callingfirebase.firestore()fails. - Have
firebase-adminconnect to the emulators directly, by providing an explicitdatabaseURLand firestore URLs, and overridingcredential.getAccessToken()to returnowner. Now the issue is that the admin's implementation of firestore expects a service account and throws on the credentials override: https://github.com/firebase/firebase-admin-node/blob/master/src/firestore/firestore.ts#L95-L100 - Return the firebase app as part of the setup code, so that
app.firestore()always works. This requires refactoring the whole codebase to use an app instance instead of a firebase workspace.
Is there a recommended way to connect the admin sdk to emulators?
Ikxyz, sondresorbye, zoltan-mihalyi, nicosayer, crvouga and 7 more