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

feat: Emulator support for Firestore #603

Open
3 of 12 tasks
sklink opened this issue Mar 29, 2024 · 0 comments
Open
3 of 12 tasks

feat: Emulator support for Firestore #603

sklink opened this issue Mar 29, 2024 · 0 comments

Comments

@sklink
Copy link

sklink commented Mar 29, 2024

Plugin(s)

  • Analytics
  • App
  • App Check
  • Authentication
  • Crashlytics
  • Cloud Firestore
  • Cloud Messaging
  • Cloud Storage
  • Performance
  • Remote Config

Current problem

Unable to connect to locally running Firestore emulator

Preferred solution

Would like to use the connectFirestoreEmulator method from firebase/firestore to connect to an emulator either at localhost or through a reverse proxy. Note that reverse proxy requires the initializeFirestore(app, { host }); method because connectFirestoreEmulator requires a port.

Alternative options

I did try to use the Firebase SDK methods to connect to the emulator but I can see the network requests still routing through the live Firestore url.

Additional context

I started writing a PR for this but an issue, as mentioned above, is that the connectFirestoreEmulator does not allow for host-only, making reverse proxy unusable. In that case, using initializeFirestore(app, { host }); instead works.

Here's the method for web.ts in capacitor-firebase/firestore, but I'm unsure whether initializeFirestore here is going to cause issues:

  export interface UseEmulatorOptions {
    host: string;
    port?: number;
  }
 
  // ... In the FirebaseFirestoreWeb definition

  public async useEmulator(options: UseEmulatorOptions): Promise<void> {
    const firestore = getFirestore();
    
    if (options.port) {
      connectFirestoreEmulator(firestore, options.host, options.port);
    } else {
      initializeFirestore(firestore.app, {
        host: options.host
      });
    }
  }

I have not looked at the native code to see what might need to be changed there.

Before submitting

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

2 participants