@@ -10,7 +10,6 @@ import {
1010 Auth ,
1111} from 'firebase/auth'
1212import { type App , ref , inject } from 'vue-demi'
13- import { useFirebaseApp } from '../app'
1413import { getGlobalScope } from '../globals'
1514import { isClient , _Nullable } from '../shared'
1615import { authUserMap , setupOnAuthStateChanged } from './user'
@@ -39,6 +38,17 @@ export interface VueFireAuthOptions {
3938 dependencies : AuthDependencies
4039}
4140
41+ /**
42+ * Options for VueFire Auth module when passing the auth instance directly.
43+ */
44+ export interface VueFireAuthOptionsFromAuth
45+ extends Pick < VueFireAuthOptions , 'initialUser' > {
46+ /**
47+ * Auth instance to use.
48+ */
49+ auth : Auth
50+ }
51+
4252/**
4353 * VueFire Auth Module to be added to the `VueFire` Vue plugin options. This calls the `VueFireAuthWithDependencies()`
4454 * with **all** the dependencies, increasing bundle size. Consider using `VueFireAuthWithDependencies()` instead to
@@ -81,6 +91,29 @@ export function VueFireAuth(initialUser?: _Nullable<User>): VueFireModule {
8191 */
8292export const _VueFireAuthKey = Symbol ( 'VueFireAuth' )
8393
94+ /**
95+ * VueFire Auth Module to be added to the `VueFire` Vue plugin options. It accepts an auth instance rather than the
96+ * dependencies. It allows manually calling emulators and other advanced use cases. Prefer using
97+ * `VueFireAuthWithDependencies()` and `VueFireAuth()` for most use cases.
98+ *
99+ * @param options - auth instance and initial user
100+ */
101+ export function VueFireAuthOptionsFromAuth ( {
102+ auth,
103+ initialUser,
104+ } : VueFireAuthOptionsFromAuth ) : VueFireModule {
105+ return ( firebaseApp : FirebaseApp , app : App ) => {
106+ const [ user , _auth ] = _VueFireAuthInit (
107+ firebaseApp ,
108+ app ,
109+ initialUser ,
110+ undefined ,
111+ auth
112+ )
113+ setupOnAuthStateChanged ( user , _auth )
114+ }
115+ }
116+
84117/**
85118 * VueFire Auth Module to be added to the `VueFire` Vue plugin options. It accepts dependencies to pass to
86119 * `initializeAuth()` to better control the bundle size.
@@ -110,14 +143,14 @@ export function _VueFireAuthInit(
110143 firebaseApp : FirebaseApp ,
111144 app : App ,
112145 initialUser : _Nullable < User > ,
113- dependencies : AuthDependencies
146+ dependencies ?: AuthDependencies ,
147+ auth = initializeAuth ( firebaseApp , dependencies )
114148) {
115149 const user = getGlobalScope ( firebaseApp , app ) . run ( ( ) =>
116150 ref < _Nullable < User > > ( initialUser )
117151 ) !
118152 // TODO: Is it okay to have it both server and client?
119153 authUserMap . set ( firebaseApp , user )
120- const auth = initializeAuth ( firebaseApp , dependencies )
121154 app . provide ( _VueFireAuthKey , auth )
122155
123156 return [ user , auth ] as const
0 commit comments