Skip to content

two attempts to connect to auth emulator cause config error #6824

@joaomelo

Description

@joaomelo

[REQUIRED] Environment info

firebase-tools: 11.14.3
Platform: Windows 11

[REQUIRED] Test case

This repo commit.

[REQUIRED] Steps to reproduce

Clone the repo, install the project dependencies with npm i and firebase tools globally, open the windows terminal, and start emulators with firebase emulators:exec --project demo-test "vitest run"

[REQUIRED] Expected behavior

All test cases are able to connect to firebase emulators.

[REQUIRED] Actual behavior

After a test case connect to the emulators, the following ones will throw an error of config failed. See image:

error

But if we changed the connection code from this...

function connectToFirebase(connection) {
  const { useEmulators, ...config } = connection;

  const app = initializeApp(config);
  const auth = getAuth(app);
  const db = getFirestore(app);

  if (useEmulators) {
    connectAuthEmulator(auth, "http://localhost:9099", {
      disableWarnings: true,
    });
    connectFirestoreEmulator(db, "localhost", 8080);
  }

  const firebase = { app, auth, db };
  return firebase;
}

to this...

function connectToFirebase(connection) {
  const { useEmulators, ...config } = connection;

  const app = initializeApp(config);
  const auth = getAuth(app);
  const db = getFirestore(app);

  if (useEmulators && !auth.config.emulator) {
    connectAuthEmulator(auth, "http://localhost:9099", {
      disableWarnings: true,
    });
    connectFirestoreEmulator(db, "localhost", 8080);
  }

  const firebase = { app, auth, db };
  return firebase;
}

all connections go through all right.

pass

I'm claiming this is a bug since there is no documented spec that claims a second connection attempt would fail and that the hack adopted here (!auth.config.emulator) uses an undocumented property that could change anytime. The consequence would be a fragile code that can be easily broken in a future path or minor release.

Thanks.
JM

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions