@@ -77,6 +77,7 @@ export function VueFireAuth(initialUser?: _Nullable<User>): VueFireModule {
7777/**
7878 * Key to be used to inject the auth instance into components. It allows avoiding to call `getAuth()`, which isn't tree
7979 * shakable.
80+ * @internal
8081 */
8182export const _VueFireAuthKey = Symbol ( 'VueFireAuth' )
8283
@@ -91,17 +92,37 @@ export function VueFireAuthWithDependencies({
9192 initialUser,
9293} : VueFireAuthOptions ) : VueFireModule {
9394 return ( firebaseApp : FirebaseApp , app : App ) => {
94- const user = getGlobalScope ( firebaseApp , app ) . run ( ( ) =>
95- ref < _Nullable < User > > ( initialUser )
96- ) !
97- // this should only be on client
98- authUserMap . set ( firebaseApp , user )
99- const auth = initializeAuth ( firebaseApp , dependencies )
100- app . provide ( _VueFireAuthKey , auth )
95+ const [ user , auth ] = _VueFireAuthInit (
96+ firebaseApp ,
97+ app ,
98+ initialUser ,
99+ dependencies
100+ )
101101 setupOnAuthStateChanged ( user , auth )
102102 }
103103}
104104
105+ /**
106+ * initializes auth for both the server and client.
107+ * @internal
108+ */
109+ export function _VueFireAuthInit (
110+ firebaseApp : FirebaseApp ,
111+ app : App ,
112+ initialUser : _Nullable < User > ,
113+ dependencies : AuthDependencies
114+ ) {
115+ const user = getGlobalScope ( firebaseApp , app ) . run ( ( ) =>
116+ ref < _Nullable < User > > ( initialUser )
117+ ) !
118+ // TODO: Is it okay to have it both server and client?
119+ authUserMap . set ( firebaseApp , user )
120+ const auth = initializeAuth ( firebaseApp , dependencies )
121+ app . provide ( _VueFireAuthKey , auth )
122+
123+ return [ user , auth ] as const
124+ }
125+
105126/**
106127 * Retrieves the Firebase Auth instance. **Returns `null` on the server**. When using this function on the client in
107128 * TypeScript, you can force the type with `useFirebaseAuth()!`.
0 commit comments