vuejs / vuefire

🔥 Firebase bindings for Vue.js
https://vuefire.vuejs.org
MIT License
3.82k stars 323 forks source link

Firebase Auth tree shaking #1459

Closed harwoodspike closed 7 months ago

harwoodspike commented 7 months ago

What problem is this solving

The current VueFire uses getAuth in the authentication module, but according to https://firebase.google.com/docs/auth/web/custom-dependencies that imports all of the authentication module and doesn't remove anything in the tree shaking process.

So I am trying to solve the tree shaking issue while adding more flexibility.

Proposed solution

I propose that we add the ability to optionally pass the Auth object into VueFire.

In my project I build the Auth object using initializeAuth which should properly tree shake. It would be awesome to pass that into VueFire so that VueFire doesn't use getAuth which in turn should allow proper tree shaking.

Describe alternatives you've considered

No response

posva commented 7 months ago

I wasn’t aware of this issue. It should be doable without breaking changes I believe

harwoodspike commented 6 months ago

@posva Thanks for the ability to customize the Auth dependencies.

I would like to know if it would be possible to add a VueFireAuth module that accepts the Auth instance like:

export function VueFireAuthFromAuth({
  auth,
  initialUser,
}: VueFireAuthOptions): VueFireModule {
  return (firebaseApp: FirebaseApp, app: App) => {
    const [user, initAuth] = _VueFireAuthInit(
      firebaseApp,
      app,
      initialUser,
      undefined,
      auth
    )
    setupOnAuthStateChanged(user, initAuth)
  }
}

I propose this as I am using Vuefire without ssr or nuxt and would like to use Firebase emulators but I am unable to get the Auth instance from Vuefire outside of injectable context.

I configure all my Firebase configs in a files outside of Vue so it doesn't have injectable context.

posva commented 6 months ago

Sure. I added d5d5e1b. I think I should have gone for that solution rather than passing the dependencies. Hopefully I will publish a new version soon