Skip to content

Commit df57432

Browse files
committed
feat: useFirebaseApp in nuxt
1 parent 7dce0e0 commit df57432

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

packages/nuxt/src/module.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,11 @@ export interface VueFireNuxtModuleOptions {
4444
config: Omit<AppOptions, 'credential'>
4545

4646
/**
47-
* Firebase Admin Service Account passed to `firebase-admin`'s `initializeApp()`. Required if you are adding an adminConfig
47+
* Firebase Admin Service Account passed to `firebase-admin`'s `initializeApp()`. Required if you are adding an adminConfig.
4848
*/
4949
serviceAccount: string | ServiceAccount
5050
}
5151

52-
/**
53-
* Optional name passed to `firebase.initializeApp(config, name)`
54-
*/
55-
// TODO: is this useful?
56-
// NOTE: this should probably be inferred automatically based on the auth status to have one app per user cached on the server
57-
// appName?: string
58-
5952
/**
6053
* Enables AppCheck on the client and server. Note you only need to pass the options for the client, on the server,
6154
* the configuration will be handled automatically.
@@ -187,10 +180,16 @@ const VueFire: NuxtModule<VueFireNuxtModuleOptions> =
187180
addPlugin(resolve(runtimeDir, 'admin/plugin.server'))
188181
}
189182

190-
addVueFireImports([
183+
// these imports are overridden by nuxt-vuefire to allow being used in more places like plugins and middlewares
184+
addImports([
191185
// app
192-
{ from: 'vuefire', name: 'useFirebaseApp' },
186+
{
187+
from: resolve(runtimeDir, 'app/composables'),
188+
name: 'useFirebaseApp',
189+
},
190+
])
193191

192+
addVueFireImports([
194193
// firestore
195194
{ from: 'vuefire', name: 'useDocument' },
196195
{ from: 'vuefire', name: 'useCollection' },
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { useNuxtApp } from '#app'
2+
3+
/**
4+
* Gets the firebase instance from the current Nuxt App. This can be used anywhere the `useNuxtApp()` can be used. Differently from `vuefire`'s `useFirebaseApp()`, this doesn't accept a name.
5+
*/
6+
export const useFirebaseApp = () => useNuxtApp().$firebaseApp
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { getCurrentUser as _getCurrentUser } from 'vuefire'
2-
import { useNuxtApp } from '#app'
2+
import { useFirebaseApp } from '../app/composables'
33

44
/**
55
* @inheritDoc {getCurrentUser}
66
*/
7-
export function getCurrentUser(name?: string) {
7+
export const getCurrentUser = (name?: string) =>
88
// This makes the `getCurrentUser()` function work by default in more places when using the Nuxt module
9-
return _getCurrentUser(name ?? useNuxtApp().$firebaseApp.name)
10-
}
9+
_getCurrentUser(name ?? useFirebaseApp().name)

0 commit comments

Comments
 (0)