DEV Community

Teerasak Vichadee
Teerasak Vichadee

Posted on

Fix Firebase error "auth/emulator-config-failed"

Official Document Said That

  • create app instance
  • create auth instance
  • then connect with emulator
const app = initializeApp(config.firebase)
const auth = getAuth(app)
connectAuthEmulator(auth, 'http://localhost:9099', { disableWarnings: true })
// note: 9099 is the default port Firebase used for their authen emulator
Enter fullscreen mode Exit fullscreen mode

But I got this when logged-in

Uncaught FirebaseError: Firebase: Error (auth/emulator-config-failed).
Enter fullscreen mode Exit fullscreen mode

Here's the Solution

From developer best friend Stackoverflow

async function setupEmulators(auth) {
  const authUrl = 'http://localhost:9099'
  await fetch(authUrl)
  connectAuthEmulator(auth, 'http://localhost:9099', { disableWarnings: true })
  // why? to make sure that emulator are loaded
}

const app = initializeApp(config.firebase)
const auth = getAuth(app)
setupEmulators(auth)
Enter fullscreen mode Exit fullscreen mode

Happy

Top comments (0)