Skip to content

Cannot connect to Auth Emulator more than once #8128

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

Closed
tzappia opened this issue Jan 22, 2025 · 3 comments
Closed

Cannot connect to Auth Emulator more than once #8128

tzappia opened this issue Jan 22, 2025 · 3 comments

Comments

@tzappia
Copy link

tzappia commented Jan 22, 2025

[REQUIRED] Environment info

firebase-tools: 13.29.1

Platform: macOS

[REQUIRED] Test case

Initialize the Auth Emulator as part of a server side rendering flow using FirebaseServerApp. A sample app is provided with the latest release of AngularFire.

[REQUIRED] Steps to reproduce

In an environment using emulators, initialize the app, authenticate, and then reload the page.

[REQUIRED] Expected behavior

No errors should be observed when reloading the page.

[REQUIRED] Actual behavior

The app crashes with the error: auth/emulator-config-failed

Additional notes

I see that in the AngularFire sample app, they have included this check to ensure the emulator doesn't get initialized twice.

if ((auth as any)._canInitEmulator && environment.emulatorPorts?.auth) {
  connectAuthEmulator(auth, `http://localhost:${environment.emulatorPorts.auth}`, { disableWarnings: true });
}

This is a workaround that shouldn't have to rely on internal properties. Other emulators (Storage, Firestore, etc.) are able to be connected to multiple times successfully without error.

@aalej
Copy link
Contributor

aalej commented Jan 23, 2025

Thanks for reaching out, @tzappia. It seems like the error is thrown here. From what I can gather, when the JavaScript SDK has made a request to the emulator(initialized a connection), trying to call connectAuthEmulator again would raise the auth/emulator-config-failed error.

I’m able to reproduce the error from the sample by commenting out the condition that checks if the connection to the emulator has been initialized:

     // if ((auth as any)._canInitEmulator && environment.emulatorPorts?.auth) {
     connectAuthEmulator(
       auth,
       `http://localhost:${environment.emulatorPorts.auth}`,
       { disableWarnings: true }
     );
     // }

Since the error is coming from the client SDK, I’d recommend filing an issue to the Firebase JavaScript SDK repository so that they can take a look.

@tzappia
Copy link
Author

tzappia commented Jan 23, 2025

Thanks for investigating @aalej . It seems there was an existing bug open for this issue since 2022. I think it may be more of a problem now that SSR is gaining traction. I think it's a bad sign that the AngularFire put in a hack for it and that they haven't coordinated with the Firebase team to figure out a resolution. Are you able to bump the old bug report in the JS SDK repo with someone internally so it doesn't stay lost? Will it get more attention if I just open a brand new bug report?

@aalej
Copy link
Contributor

aalej commented Jan 24, 2025

Thanks for sharing that issue @tzappia. I agree with you here, since SSR application are becoming more popular, I do see this causing some issues when trying to use the emulators.

Reading through the bug, I think the proposed solution was exposing a emulatorInitialized() method that can be used to check if it is still possible to call connectAuthEmulator. I wonder if it would be possible to instead add a condition similar to if ((auth as any)._canInitEmulator && environment.emulatorPorts?.auth) into the connectAuthEmulator method.

Let me try to ping some folks to see what we can do here.

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