@@ -10,7 +10,6 @@ import {
10
10
Auth ,
11
11
} from 'firebase/auth'
12
12
import { type App , ref , inject } from 'vue-demi'
13
- import { useFirebaseApp } from '../app'
14
13
import { getGlobalScope } from '../globals'
15
14
import { isClient , _Nullable } from '../shared'
16
15
import { authUserMap , setupOnAuthStateChanged } from './user'
@@ -39,6 +38,17 @@ export interface VueFireAuthOptions {
39
38
dependencies : AuthDependencies
40
39
}
41
40
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
+
42
52
/**
43
53
* VueFire Auth Module to be added to the `VueFire` Vue plugin options. This calls the `VueFireAuthWithDependencies()`
44
54
* with **all** the dependencies, increasing bundle size. Consider using `VueFireAuthWithDependencies()` instead to
@@ -81,6 +91,29 @@ export function VueFireAuth(initialUser?: _Nullable<User>): VueFireModule {
81
91
*/
82
92
export const _VueFireAuthKey = Symbol ( 'VueFireAuth' )
83
93
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
+
84
117
/**
85
118
* VueFire Auth Module to be added to the `VueFire` Vue plugin options. It accepts dependencies to pass to
86
119
* `initializeAuth()` to better control the bundle size.
@@ -110,14 +143,14 @@ export function _VueFireAuthInit(
110
143
firebaseApp : FirebaseApp ,
111
144
app : App ,
112
145
initialUser : _Nullable < User > ,
113
- dependencies : AuthDependencies
146
+ dependencies ?: AuthDependencies ,
147
+ auth = initializeAuth ( firebaseApp , dependencies )
114
148
) {
115
149
const user = getGlobalScope ( firebaseApp , app ) . run ( ( ) =>
116
150
ref < _Nullable < User > > ( initialUser )
117
151
) !
118
152
// TODO: Is it okay to have it both server and client?
119
153
authUserMap . set ( firebaseApp , user )
120
- const auth = initializeAuth ( firebaseApp , dependencies )
121
154
app . provide ( _VueFireAuthKey , auth )
122
155
123
156
return [ user , auth ] as const
0 commit comments