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

Closed
bunyaminmrcn opened this issue Sep 25, 2024 · 6 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 next-auth@4.24.7

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.

@bunyaminmrcn
Copy link
Author

bunyaminmrcn commented Sep 28, 2024

Put initEmulator to directly in component doesn't effect . I am using Next . Its run on the backend first and window is not defined. It gives an error

@jbalidiong
Copy link
Contributor

Hi @bunyaminmrcn, I tried replicating the issue but wasn't able to reproduce the same behavior. I created this repo to try and replicate the setup you have. In case I missed anything or made a mistake with the setup, just let me know. Alternatively, any chance you could provide an MCVE to help us replicate the issue?

@google-oss-bot
Copy link
Contributor

Hey @bunyaminmrcn. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link
Contributor

Since there haven't been any recent updates here, I am going to close this issue.

@bunyaminmrcn if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

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