@@ -77,6 +77,7 @@ export function VueFireAuth(initialUser?: _Nullable<User>): VueFireModule {
77
77
/**
78
78
* Key to be used to inject the auth instance into components. It allows avoiding to call `getAuth()`, which isn't tree
79
79
* shakable.
80
+ * @internal
80
81
*/
81
82
export const _VueFireAuthKey = Symbol ( 'VueFireAuth' )
82
83
@@ -91,17 +92,37 @@ export function VueFireAuthWithDependencies({
91
92
initialUser,
92
93
} : VueFireAuthOptions ) : VueFireModule {
93
94
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
+ )
101
101
setupOnAuthStateChanged ( user , auth )
102
102
}
103
103
}
104
104
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
+
105
126
/**
106
127
* Retrieves the Firebase Auth instance. **Returns `null` on the server**. When using this function on the client in
107
128
* TypeScript, you can force the type with `useFirebaseAuth()!`.
0 commit comments