Skip to content

getAuth method incompatible with hot reloading #4545

Closed
@markjaniczak

Description

@markjaniczak

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions