Skip to content

getAuth method incompatible with hot reloading #4545

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
markjaniczak opened this issue Feb 26, 2021 · 2 comments
Closed

getAuth method incompatible with hot reloading #4545

markjaniczak opened this issue Feb 26, 2021 · 2 comments

Comments

@markjaniczak
Copy link

markjaniczak commented Feb 26, 2021

Describe your environment

  • Operating System version: MacOS Big Sur 11.2.1
  • Browser version: Edge 88.0.705.74
  • Firebase SDK version: 0.900.15
  • Firebase Product: auth

Describe the problem

The getAuth function appears to always initialise a new instance when called. So in a Next.JS app that hot reloads you'll get the auth/already-initialized error.

The getApp method doesn't initialise a new app, it only returns the default or specified app. Combined with getApps, that pattern can be used to do an effective quick check to prevent duplicate instances:

// firebaseClient.js
import { initializeApp, getApps } from "firebase/app";

if (getApps().length === 0) {
  initializeApp({
    // ...config
  });
}

There doesn't appear to be a method for checking for existing instances before calling getAuth and I suspect the problem is the same for firestore, database etc. as the documentation suggests they also create a new instance when called.

@Feiyang1
Copy link
Member

Thanks for the report. It will be fixed by #4519 once it's released

@retronav
Copy link

retronav commented Mar 7, 2021

@markjaniczak Till the release comes out, you can follow up the conversation in #4510. That'll probably help you.
Thanks.

@firebase firebase locked and limited conversation to collaborators Mar 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants