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

Firebase client sometimes tries to production server while using connectAuthEmulator #8519

Open
bunyaminmrcn opened this issue Sep 25, 2024 · 2 comments

Comments

@bunyaminmrcn
Copy link

Operating System

Kali Linux

Environment (if applicable)

Chrome 129, Firefox 130

Firebase SDK Version

10.13.2

Firebase SDK Product(s)

Auth

Project Tooling

next project with [email protected]

Detailed Problem Description

I set it up local emulator for firebase auth & firestore & storage & functions. But issue happen while authorizing

Steps and code to reproduce issue

I run initEmulator function in useEffect hook after login. It asks to credentials to production server
(https://identitytoolkit.googleapis.com/v1/accounts:lookup)

import { initializeApp, getApp } from 'firebase/app';
import { connectAuthEmulator, getAuth } from 'firebase/auth';

const firebaseConfig = {
  apiKey: "test",
  authDomain: 'http://127.0.0.1:9099',
  databaseURL: "http://127.0.0.1:8080",
  projectId: "test",
};

const firebaseApp = initializeApp(firebaseConfig);

let initialized = false;
const initEmulator = () => {
  if (!initialized) {
    try {
      
      connectAuthEmulator(firebaseAuth, 'http://127.0.0.1:9099')
      console.log("Connected to Emulator")
      initialized = true;
    } catch(err) {
      console.log("Error occured")
    }
    
  }
}

const firebaseAuth = getAuth(firebaseApp)
export { firebaseApp, firebaseAuth, initEmulator }


@bunyaminmrcn bunyaminmrcn added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Sep 25, 2024
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@bunyaminmrcn bunyaminmrcn changed the title Firebase client always tries to production server while using connectAuthEmulator Firebase client sometimes tries to production server while using connectAuthEmulator Sep 25, 2024
@jbalidiong jbalidiong added api: auth needs-attention testing-sdk testing with emulator and removed needs-triage new A new issue that hasn't be categoirzed as question, bug or feature request labels Sep 25, 2024
@hsubox76
Copy link
Contributor

I'm not sure I am understanding correctly - you're running initEmulator after login? Isn't it too late? Doesn't the login operation itself call the backend, if no emulator has been initialized? Or do you mean you're running it after initializing auth, not login?

Regardless, useEffect has some weird timing and usually happens after initial page load. I don't think I'd feel safe putting anything in there that I want to run before the rest of my code. I'd probably start the emulator outside of any component. It's not a UI operation.

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

4 participants