Skip to content

API Documentation / vuefire

Module: vuefire

Interfaces

References

rtdbPlugin

Renames and re-exports databasePlugin

Type Aliases

FirebaseOption

Ƭ FirebaseOption: VueFirebaseObject | () => VueFirebaseObject


FirestoreOption

Ƭ FirestoreOption: VueFirestoreObject | () => VueFirestoreObject


UseListOptions

Ƭ UseListOptions<DataT>: UseDatabaseRefOptions<DataT>

Type parameters

NameType
DataTunknown

UseObjectOptions

Ƭ UseObjectOptions<DataT>: UseDatabaseRefOptions<DataT>

Type parameters

NameType
DataTunknown

VueDatabaseDocumentData

Ƭ VueDatabaseDocumentData<T>: null | T & { id: string }

Type used by default by the serialize option.

Type parameters

NameType
Tunknown

VueDatabaseQueryData

Ƭ VueDatabaseQueryData<T>: _Simplify<NonNullable<VueDatabaseDocumentData<T>>>[]

Same as VueDatabaseDocumentData but for a query.

Type parameters

NameType
Tunknown

VueFirebaseObject

Ƭ VueFirebaseObject: Record<string, Query | DatabaseReference>


VueFirestoreDocumentData

Ƭ VueFirestoreDocumentData<T>: null | T & { id: string }

Type used by default by the firestoreDefaultConverter.

Type parameters

NameType
TDocumentData

VueFirestoreObject

Ƭ VueFirestoreObject: Record<string, _FirestoreDataSource>


VueFirestoreQueryData

Ƭ VueFirestoreQueryData<T>: _Simplify<NonNullable<VueFirestoreDocumentData<T>>>[]

Type parameters

NameType
TDocumentData

Variables

devalueCustomParsers

Const devalueCustomParsers: Object

Custom parsers for devalue to support Firestore Timestamp and GeoPoint on SSR.

Type declaration

NameType
GeoPoint(data: { latitude: number ; longitude: number }) => GeoPoint
TimeStamp(data: { nanoseconds: number ; seconds: number }) => Timestamp

devalueCustomStringifiers

Const devalueCustomStringifiers: Object

Custom stringifier for devalue to support Firestore Timestamp and GeoPoint on SSR.

Type declaration

NameType
GeoPoint(data: unknown) => false | { latitude: number ; longitude: number }
TimeStamp(data: unknown) => false | { nanoseconds: number ; seconds: number }

firestoreDefaultConverter

Const firestoreDefaultConverter: FirestoreDataConverter<VueFirestoreDocumentData>

Default converter for Firestore data. Can be overridden globally by setting globalFirestoreOptions.converter.


globalDatabaseOptions

Const globalDatabaseOptions: _DatabaseRefOptionsWithDefaults


globalFirestoreOptions

Const globalFirestoreOptions: _FirestoreRefOptionsWithDefaults

Global default options

Functions

VueFire

VueFire(app, «destructured»): void

VueFire Vue plugin.

Parameters

NameType
appApp<any>
«destructured»VueFireOptions

Returns

void


VueFireAppCheck

VueFireAppCheck(options): (firebaseApp: FirebaseApp, app: App<any>) => void

VueFire AppCheck Module to be added to the VueFire Vue plugin options. This module is client only and shouldn't be added on server.

Parameters

NameType
optionsVueFireAppCheckOptions

Returns

fn

▸ (firebaseApp, app): void

Parameters
NameType
firebaseAppFirebaseApp
appApp<any>
Returns

void

Example

ts
import { createApp } from 'vue'
import { VueFire, VueFireAppCheck } from 'vuefire'

const app = createApp(App)
app.use(VueFire, {
  modules: [VueFireAppCheck()],
})

VueFireAuth

VueFireAuth(initialUser?): VueFireModule

VueFire Auth Module to be added to the VueFire Vue plugin options. This calls the VueFireAuthWithDependencies() with all the dependencies, increasing bundle size. Consider using VueFireAuthWithDependencies() instead to better control the bundle size.

Parameters

NameTypeDescription
initialUser?_Nullable<User>initial value of the user. used for SSR

Returns

VueFireModule

See

https://firebase.google.com/docs/auth/web/custom-dependencies

Example

ts
import { createApp } from 'vue'
import { VueFire, VueFireAuth } from 'vuefire'

const app = createApp(App)
app.use(VueFire, {
 modules: [VueFireAuth()],
})

VueFireAuthOptionsFromAuth

VueFireAuthOptionsFromAuth(options): VueFireModule

VueFire Auth Module to be added to the VueFire Vue plugin options. It accepts an auth instance rather than the dependencies. It allows manually calling emulators and other advanced use cases. Prefer using VueFireAuthWithDependencies() and VueFireAuth() for most use cases.

Parameters

NameTypeDescription
optionsVueFireAuthOptionsFromAuthauth instance and initial user

Returns

VueFireModule


VueFireAuthWithDependencies

VueFireAuthWithDependencies(options): VueFireModule

VueFire Auth Module to be added to the VueFire Vue plugin options. It accepts dependencies to pass to initializeAuth() to better control the bundle size.

Parameters

NameTypeDescription
optionsVueFireAuthOptionsuser and options to pass to initializeAuth().

Returns

VueFireModule


VueFireDatabaseOptionsAPI

VueFireDatabaseOptionsAPI(pluginOptions?): (firebaseApp: FirebaseApp, app: App<any>) => void

VueFire Database Module to be added to the VueFire Vue plugin options. If you exclusively use the Composition API (e.g. useDatabaseObject() and useDatabaseList()), you should not add it.

Parameters

NameType
pluginOptions?DatabasePluginOptions

Returns

fn

▸ (firebaseApp, app): void

Parameters
NameType
firebaseAppFirebaseApp
appApp<any>
Returns

void

Example

ts
import { createApp } from 'vue'
import { VueFire, VueFireDatabaseOptionsAPI } from 'vuefire'

const app = createApp(App)
app.use(VueFire, {
  modules: [VueFireDatabaseOptionsAPI()],
})

VueFireFirestoreOptionsAPI

VueFireFirestoreOptionsAPI(pluginOptions?): (firebaseApp: FirebaseApp, app: App<any>) => void

VueFire Firestore Module to be added to the VueFire Vue plugin options.

Parameters

NameType
pluginOptions?FirestorePluginOptions

Returns

fn

▸ (firebaseApp, app): void

Parameters
NameType
firebaseAppFirebaseApp
appApp<any>
Returns

void

Example

ts
import { createApp } from 'vue'
import { VueFire, VueFireFirestoreOptionsAPI } from 'vuefire'

const app = createApp(App)
app.use(VueFire, {
  modules: [VueFireFirestoreOptionsAPI()],
})

databaseDefaultSerializer

databaseDefaultSerializer(snapshot): VueDatabaseDocumentData<unknown>

Convert firebase Database snapshot of a ref that exists into a bindable data record.

Parameters

NameType
snapshotDataSnapshot

Returns

VueDatabaseDocumentData<unknown>


databasePlugin

databasePlugin(app, pluginOptions?, firebaseApp?): void

Install this plugin if you want to add $databaseBind and $databaseUnbind functions. Note this plugin is only necessary if you use the Options API. If you exclusively use the Composition API (e.g. useDatabaseObject() and useDatabaseList()), you should not add it.

Parameters

NameType
appApp<any>
pluginOptions?DatabasePluginOptions
firebaseApp?FirebaseApp

Returns

void

Deprecated

Use VueFire and VueFireDatabaseOptionsAPI with the modules option instead.


firestorePlugin

firestorePlugin(app, pluginOptions?, firebaseApp?): void

Install this plugin to add $firestoreBind and $firestoreUnbind functions. Note this plugin is not necessary if you exclusively use the Composition API (useDocument() and useCollection()).

Parameters

NameType
appApp<any>
pluginOptions?FirestorePluginOptions
firebaseApp?FirebaseApp

Returns

void

Deprecated

Use VueFire and VueFireFirestoreOptionsAPI with the modules option instead.b


getCurrentUser

getCurrentUser(name?): Promise<_Nullable<User>>

Returns a promise that resolves the current user once the user is loaded. Must be called after the firebase app is initialized.

Parameters

NameTypeDescription
name?stringname of the firebase application

Returns

Promise<_Nullable<User>>


updateCurrentUserProfile

updateCurrentUserProfile(profile): Promise<void>

Updates the current user profile and updates the current user state. This function internally calls updateProfile() from 'firebase/auth' and then updates the current user state.

Parameters

NameTypeDescription
profileObjectthe new profile information
profile.displayName?_Nullable<string>-
profile.photoURL?_Nullable<string>-

Returns

Promise<void>


useAppCheck

useAppCheck(name?): AppCheck

Retrieves the Firebase App Check instance.

Parameters

NameTypeDescription
name?stringname of the application

Returns

AppCheck


useAppCheckToken

useAppCheckToken(): Ref<undefined | string>

The current app-check token as a Ref. Note this ref is always undefined on the server.

Returns

Ref<undefined | string>


useCollection

useCollection<R>(collectionRef, options?): _RefFirestore<_InferReferenceType<R>[]>

Creates a reactive collection (usually an array) of documents from a collection ref or a query from Firestore. Extracts the type of the query or converter.

Type parameters

NameType
Rextends Query<unknown, DocumentData> | CollectionReference<unknown, DocumentData>

Parameters

NameTypeDescription
collectionRefMaybeRefOrGetter<_Nullable<R>>query or collection
options?UseCollectionOptions<_InferReferenceType<R>[]>optional options

Returns

_RefFirestore<_InferReferenceType<R>[]>

useCollection<T>(collectionRef, options?): _RefFirestore<VueFirestoreQueryData<T>>

Creates a reactive collection (usually an array) of documents from a collection ref or a query from Firestore. Accepts a generic to enforce the type of the returned Ref. Note you can (and probably should) use .withConverter() to have stricter type safe version of a collection reference.

Type parameters

Name
T

Parameters

NameTypeDescription
collectionRefMaybeRefOrGetter<_Nullable<Query<unknown, DocumentData> | CollectionReference<unknown, DocumentData>>>query or collection
options?UseCollectionOptions<T[]>optional options

Returns

_RefFirestore<VueFirestoreQueryData<T>>


useCurrentUser

useCurrentUser(name?): Ref<_Nullable<User>>

Returns a reactive variable of the currently authenticated user in the firebase app. The ref is null if no user is authenticated or when the user logs out. The ref is undefined until the user is initially loaded.

Parameters

NameTypeDescription
name?stringname of the application

Returns

Ref<_Nullable<User>>


useDatabase

useDatabase(name?): Database

Retrieves the Database instance.

Parameters

NameTypeDescription
name?stringname of the application

Returns

Database

the Database instance


useDatabaseList

useDatabaseList<T>(reference, options?): _RefDatabase<VueDatabaseQueryData<T>>

Creates a reactive variable connected to the database as an array. Each element in the array will contain an id property. Note that if you override the serialize option, it should also set an id property in order for this to work.

Type parameters

NameType
Tunknown

Parameters

NameTypeDescription
referenceMaybeRefOrGetter<_Nullable<Query | DatabaseReference>>Reference or query to the database
options?UseListOptions<T>optional options

Returns

_RefDatabase<VueDatabaseQueryData<T>>


useDatabaseObject

useDatabaseObject<T>(reference, options?): _RefDatabase<VueDatabaseDocumentData<T> | undefined>

Creates a reactive variable connected to the database as an object. If the reference is a primitive, it will be converted to an object containing a $value property with the primitive value and an id property with the reference's key.

Type parameters

NameType
Tunknown

Parameters

NameTypeDescription
referenceMaybeRefOrGetter<_Nullable<DatabaseReference>>Reference or query to the database
options?UseObjectOptions<T>optional options

Returns

_RefDatabase<VueDatabaseDocumentData<T> | undefined>


useDocument

useDocument<R>(documentRef, options?): _RefFirestore<_InferReferenceType<R> | undefined>

Creates a reactive document from a document ref from Firestore. Automatically extracts the type of the converter or the document.

Type parameters

NameType
Rextends DocumentReference<unknown, DocumentData>

Parameters

NameTypeDescription
documentRefMaybeRefOrGetter<_Nullable<R>>document reference
options?UseDocumentOptions<_InferReferenceType<R>>optional options

Returns

_RefFirestore<_InferReferenceType<R> | undefined>

useDocument<T>(documentRef, options?): _RefFirestore<VueFirestoreDocumentData<T> | undefined>

Creates a reactive collection (usually an array) of documents from a collection ref or a query from Firestore. Accepts a generic to enforce the type of the returned Ref. Note you can (and probably should) use .withConverter() to have stricter type safe version of a collection reference.

Type parameters

Name
T

Parameters

NameTypeDescription
documentRefMaybeRefOrGetter<_Nullable<DocumentReference<DocumentData, DocumentData>>>query or collection
options?UseDocumentOptions<T>optional options

Returns

_RefFirestore<VueFirestoreDocumentData<T> | undefined>


useFirebaseApp

useFirebaseApp(name?): FirebaseApp

Gets the firebase app instance.

Parameters

NameTypeDescription
name?stringoptional firebase app name

Returns

FirebaseApp

the firebase app


useFirebaseAuth

useFirebaseAuth(): Auth | null

Retrieves the Firebase Auth instance. Returns null on the server. When using this function on the client in TypeScript, you can force the type with useFirebaseAuth()!.

Returns

Auth | null

the Auth instance


useFirebaseStorage

useFirebaseStorage(name?): FirebaseStorage

Retrieves the Storage instance.

Parameters

NameTypeDescription
name?stringname of the application

Returns

FirebaseStorage

the Database instance


useFirestore

useFirestore(name?): Firestore

Retrieves the Firestore instance.

Parameters

NameTypeDescription
name?stringname of the application

Returns

Firestore

the Firestore instance


useIsCurrentUserLoaded

useIsCurrentUserLoaded(name?): ComputedRef<boolean>

Helper that returns a computed boolean that becomes true as soon as the current user is no longer undefined. Note this doesn't ensure the user is logged in, only if the initial signing process has run.

Parameters

NameTypeDescription
name?stringname of the application

Returns

ComputedRef<boolean>


useList

useList<T>(reference, options?): _RefDatabase<VueDatabaseQueryData<T>>

Type parameters

NameType
Tunknown

Parameters

NameType
referenceMaybeRefOrGetter<_Nullable<Query | DatabaseReference>>
options?UseListOptions<T>

Returns

_RefDatabase<VueDatabaseQueryData<T>>

Deprecated

use useDatabaseList() instead


useObject

useObject<T>(reference, options?): _RefDatabase<VueDatabaseDocumentData<T> | undefined>

Type parameters

NameType
Tunknown

Parameters

NameType
referenceMaybeRefOrGetter<_Nullable<DatabaseReference>>
options?UseObjectOptions<T>

Returns

_RefDatabase<VueDatabaseDocumentData<T> | undefined>

Deprecated

use useDatabaseObject() instead


usePendingPromises

usePendingPromises(app?): Promise<readonly [string, unknown][]>

Allows awaiting for all pending data sources. Useful to wait for SSR

Parameters

NameTypeDescription
app?FirebaseAppthe firebase app

Returns

Promise<readonly [string, unknown][]>

  • a Promise that resolves with an array of all the resolved pending promises

useSSRInitialState

useSSRInitialState(initialState, firebaseApp): SSRStore

Allows getting the initial state set during SSR on the client.

Parameters

NameTypeDescription
initialStateundefined | SSRStorethe initial state to set for the firebase app during SSR. Pass undefined to not set it
firebaseAppFirebaseAppthe firebase app to get the initial state for

Returns

SSRStore

the initial states for the current firebaseApp


useStorage

useStorage(name?): FirebaseStorage

Parameters

NameType
name?string

Returns

FirebaseStorage

Deprecated

use useFirebaseStorage() instead


useStorageFile

useStorageFile(storageRef): Object

Reactive information (url, metadata) of a StorageReference. Allows updating and deleting the storage object.

Parameters

NameTypeDescription
storageRefMaybeRefOrGetter<_Nullable<StorageReference>>StorageReference

Returns

Object

NameType
metadataShallowRef<undefined | null | FullMetadata>
refresh() => Promise<[null | string, null | FullMetadata]>
snapshotShallowRef<undefined | null | UploadTaskSnapshot>
updateMetadata(newMetadata: SettableMetadata) => Promise<null | FullMetadata>
upload(newData: Blob | Uint8Array | ArrayBuffer, newMetadata?: UploadMetadata) => undefined | Promise<unknown>
uploadErrorShallowRef<undefined | null | StorageError>
uploadProgressComputedRef<null | number>
uploadTaskShallowRef<undefined | null | UploadTask>
urlRef<undefined | null | string>

useStorageFileMetadata

useStorageFileMetadata(storageRef): Object

Returns a reactive version of the metadata of a StorageReference. Updates automatically if the StorageReference changes.

Parameters

NameTypeDescription
storageRefMaybeRefOrGetter<_Nullable<StorageReference>>StorageReference

Returns

Object

NameType
metadataShallowRef<undefined | null | FullMetadata>
promiseShallowRef<Promise<null | FullMetadata>>
refresh() => Promise<null | FullMetadata>
update(newMetadata: SettableMetadata) => Promise<null | FullMetadata>

useStorageFileUrl

useStorageFileUrl(storageRef): Object

Retrieves a reactive download URL of a StorageReference. Updates automatically if the StorageReference changes.

Parameters

NameTypeDescription
storageRefMaybeRefOrGetter<_Nullable<StorageReference>>StorageReference

Returns

Object

NameType
promiseShallowRef<Promise<null | string>>
refresh() => Promise<null | string>
urlRef<undefined | null | string>

useStorageMetadata

useStorageMetadata(storageRef): Object

Parameters

NameType
storageRefMaybeRefOrGetter<_Nullable<StorageReference>>

Returns

Object

NameType
metadataShallowRef<undefined | null | FullMetadata>
promiseShallowRef<Promise<null | FullMetadata>>
refresh() => Promise<null | FullMetadata>
update(newMetadata: SettableMetadata) => Promise<null | FullMetadata>

Deprecated

use useStorageFileMetadata() instead


useStorageObject

useStorageObject(storageRef): Object

Parameters

NameType
storageRefMaybeRefOrGetter<_Nullable<StorageReference>>

Returns

Object

NameType
metadataShallowRef<undefined | null | FullMetadata>
refresh() => Promise<[null | string, null | FullMetadata]>
snapshotShallowRef<undefined | null | UploadTaskSnapshot>
updateMetadata(newMetadata: SettableMetadata) => Promise<null | FullMetadata>
upload(newData: Blob | Uint8Array | ArrayBuffer, newMetadata?: UploadMetadata) => undefined | Promise<unknown>
uploadErrorShallowRef<undefined | null | StorageError>
uploadProgressComputedRef<null | number>
uploadTaskShallowRef<undefined | null | UploadTask>
urlRef<undefined | null | string>

Deprecated

use useStorageFile() instead


useStorageUrl

useStorageUrl(storageRef): Object

Parameters

NameType
storageRefMaybeRefOrGetter<_Nullable<StorageReference>>

Returns

Object

NameType
promiseShallowRef<Promise<null | string>>
refresh() => Promise<null | string>
urlRef<undefined | null | string>

Deprecated

use useStorageFileUrl() instead

Released under the MIT License.