|
1 | 1 | import { fileURLToPath } from 'node:url' |
2 | 2 | import { normalize } from 'node:path' |
3 | 3 | import { |
| 4 | + addImports, |
4 | 5 | addPlugin, |
5 | 6 | addPluginTemplate, |
6 | 7 | addServerHandler, |
@@ -127,43 +128,71 @@ const VueFire: NuxtModule<VueFireNuxtModuleOptions> = |
127 | 128 | }) |
128 | 129 | } |
129 | 130 |
|
130 | | - // this allows us to the order of the plugins |
131 | | - nuxt.hook('modules:done', () => { |
132 | | - if (options.auth) { |
133 | | - addPlugin(resolve(runtimeDir, 'auth/plugin.client')) |
134 | | - // must be added after the admin module to use the admin app |
135 | | - addPlugin(resolve(runtimeDir, 'auth/plugin.server')) |
136 | | - } |
| 131 | + // NOTE: the order of the plugins is reversed, so we end by adding the app plugin which is used by all other |
| 132 | + // plugins |
137 | 133 |
|
138 | | - if (options.admin) { |
139 | | - if (!nuxt.options.ssr) { |
140 | | - console.warn( |
141 | | - '[VueFire]: The "admin" option is only used during SSR. You should reenable ssr to use it.' |
142 | | - ) |
143 | | - } |
144 | | - addPlugin(resolve(runtimeDir, 'admin/plugin.server')) |
145 | | - } |
| 134 | + if (options.auth) { |
| 135 | + addPlugin(resolve(runtimeDir, 'auth/plugin.client')) |
| 136 | + // must be added after the admin module to use the admin app |
| 137 | + addPlugin(resolve(runtimeDir, 'auth/plugin.server')) |
146 | 138 |
|
147 | | - if (options.appCheck) { |
148 | | - addPlugin(resolve(runtimeDir, 'app-check/plugin')) |
| 139 | + addVueFireImports([ |
| 140 | + // auth |
| 141 | + { from: 'vuefire', name: 'useFirebaseAuth' }, |
| 142 | + { from: 'vuefire', name: 'useCurrentUser' }, |
| 143 | + ]) |
| 144 | + } |
| 145 | + |
| 146 | + if (options.admin) { |
| 147 | + if (!nuxt.options.ssr) { |
| 148 | + console.warn( |
| 149 | + '[VueFire]: The "admin" option is only used during SSR. You should reenable ssr to use it.' |
| 150 | + ) |
149 | 151 | } |
| 152 | + addPlugin(resolve(runtimeDir, 'admin/plugin.server')) |
| 153 | + } |
150 | 154 |
|
151 | | - // plugin are added in reverse order |
152 | | - addPluginTemplate({ |
153 | | - src: normalize(resolve(templatesDir, 'plugin.ejs')), |
| 155 | + if (options.appCheck) { |
| 156 | + addPlugin(resolve(runtimeDir, 'app-check/plugin')) |
| 157 | + } |
154 | 158 |
|
155 | | - options: { |
156 | | - ...options, |
157 | | - ssr: nuxt.options.ssr, |
158 | | - }, |
159 | | - }) |
| 159 | + // plugin are added in reverse order |
| 160 | + addPluginTemplate({ |
| 161 | + src: normalize(resolve(templatesDir, 'plugin.ejs')), |
160 | 162 |
|
161 | | - // adds the firebase app to each application |
162 | | - addPlugin(resolve(runtimeDir, 'app/plugin')) |
| 163 | + options: { |
| 164 | + ...options, |
| 165 | + ssr: nuxt.options.ssr, |
| 166 | + }, |
163 | 167 | }) |
| 168 | + |
| 169 | + // adds the firebase app to each application |
| 170 | + addPlugin(resolve(runtimeDir, 'app/plugin')) |
| 171 | + |
| 172 | + addVueFireImports([ |
| 173 | + // firestore |
| 174 | + { from: 'vuefire', name: 'useDocument' }, |
| 175 | + { from: 'vuefire', name: 'useCollection' }, |
| 176 | + { from: 'vuefire', name: 'useFirestore' }, |
| 177 | + |
| 178 | + // database |
| 179 | + { from: 'vuefire', name: 'useDatabase' }, |
| 180 | + { from: 'vuefire', name: 'useDatabaseList' }, |
| 181 | + { from: 'vuefire', name: 'useDatabaseObject' }, |
| 182 | + ]) |
164 | 183 | }, |
165 | 184 | }) |
166 | 185 |
|
| 186 | +type VueFireModuleExportKeys = keyof Awaited<typeof import('vuefire')> |
| 187 | +function addVueFireImports( |
| 188 | + imports: Array<{ |
| 189 | + from: 'vuefire' |
| 190 | + name: VueFireModuleExportKeys |
| 191 | + }> |
| 192 | +) { |
| 193 | + return addImports(imports) |
| 194 | +} |
| 195 | + |
167 | 196 | export default VueFire |
168 | 197 | export type { |
169 | 198 | NuxtVueFireAppCheckOptions, |
|
0 commit comments