[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Dedicated initializer function for connecting to the Firebase emulator suite #2327

Open
CodingDoug opened this issue Oct 6, 2023 · 1 comment

Comments

@CodingDoug
Copy link

The use case involves use of two initialized instances of FirebaseApp, one for the emulator and another for an actual project. Specifically, it's desirable to programmatically copy data from one to the other without having to export then import separately.

Currently, the Admin SDK requires that an env var is set with host and port in order to connect to the emulator. This is unnecessarily complex when it comes time to init the app. For example, using Auth and Firestore together (and potentially more products) requires code like this:

import { initializeApp } from "firebase-admin/app"
import { getAuth } from "firebase-admin/auth"
import { getFirestore } from "firebase-admin/firestore"

export const remote = initializeApp()
export const remoteAuth = getAuth(remote)
export const remoteFirestore = getFirestore(remote)

process.env.FIRESTORE_EMULATOR_HOST = 'localhost:8080'
export const local = initializeApp(undefined, "local")
export const localAuth = getFirestore(local)
export const localFirestore = getFirestore(local)
delete process.env.FIRESTORE_EMULATOR_HOST

The use of the temporary env var is clunky here, and it would be more straightforward if there was a dedicated function that allowed the caller to pass the host and port instead:

const host, port = ...
export const local = initializeEmulatorApp(host, port, "local")
export const localAuth = getFirestore(local)
export const localFirestore = getFirestore(local)

Either that, or something similar to the way the web and mobile clients work for connecting to the emulator.

@google-oss-bot
Copy link

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants