From 6d27c831427866b8677b17a897adf15af187bf65 Mon Sep 17 00:00:00 2001 From: Aron Suarez Date: Tue, 18 Nov 2025 08:02:27 +0100 Subject: [PATCH 1/2] Add optional database parameter to `useFirestore` function --- src/firestore/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/firestore/index.ts b/src/firestore/index.ts index 33f03d1d..4a38b1e0 100644 --- a/src/firestore/index.ts +++ b/src/firestore/index.ts @@ -107,8 +107,9 @@ export function useDocument( * Retrieves the Firestore instance. * * @param name - name of the application + * @param database - name of the database * @returns the Firestore instance */ -export function useFirestore(name?: string) { - return getFirestore(useFirebaseApp(name)) +export function useFirestore({name, database}: {name?: string, database?: string}) { + return getFirestore(useFirebaseApp(name), database) } From 8be2d6cadbb8e4eda7862cdaff5f353a6bd4163a Mon Sep 17 00:00:00 2001 From: Aron Suarez Date: Tue, 18 Nov 2025 09:08:30 +0100 Subject: [PATCH 2/2] feat(firestore): add overload for useFirestore with direct database string Allow useFirestore to accept a database string directly as a simpler alternative to the options object. The function now supports both calling patterns: - useFirestore(databaseName) - useFirestore({ name?, database? }) When passed a string, it uses the default Firebase app with the specified database. This provides a more convenient API for the common use case of specifying only a database name. --- .gitignore | 1 + src/firestore/index.ts | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 83592a68..7882b7d7 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ roadmap.md *-debug.log docs/api .firebase +.idea diff --git a/src/firestore/index.ts b/src/firestore/index.ts index 4a38b1e0..08aec022 100644 --- a/src/firestore/index.ts +++ b/src/firestore/index.ts @@ -3,6 +3,7 @@ import { DocumentReference, Query, getFirestore, + type Firestore, } from 'firebase/firestore' import { ref, MaybeRefOrGetter } from 'vue-demi' import { useFirebaseApp } from '../app' @@ -110,6 +111,24 @@ export function useDocument( * @param database - name of the database * @returns the Firestore instance */ -export function useFirestore({name, database}: {name?: string, database?: string}) { - return getFirestore(useFirebaseApp(name), database) +export function useFirestore(database: string): Firestore +export function useFirestore(options: { + name?: string + database?: string +}): Firestore +export function useFirestore( + optionsOrDatabase: string | { name?: string; database?: string } +): Firestore { + if (typeof optionsOrDatabase === 'string') { + return getFirestore(useFirebaseApp(), optionsOrDatabase) + } + + if (optionsOrDatabase.database) { + return getFirestore( + useFirebaseApp(optionsOrDatabase.name), + optionsOrDatabase.database + ) + } + + return getFirestore(useFirebaseApp(optionsOrDatabase.name)) }