Skip to content

Commit 8be2d6c

Browse files
committed
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.
1 parent 6d27c83 commit 8be2d6c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ roadmap.md
1212
*-debug.log
1313
docs/api
1414
.firebase
15+
.idea

src/firestore/index.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
DocumentReference,
44
Query,
55
getFirestore,
6+
type Firestore,
67
} from 'firebase/firestore'
78
import { ref, MaybeRefOrGetter } from 'vue-demi'
89
import { useFirebaseApp } from '../app'
@@ -110,6 +111,24 @@ export function useDocument<T>(
110111
* @param database - name of the database
111112
* @returns the Firestore instance
112113
*/
113-
export function useFirestore({name, database}: {name?: string, database?: string}) {
114-
return getFirestore(useFirebaseApp(name), database)
114+
export function useFirestore(database: string): Firestore
115+
export function useFirestore(options: {
116+
name?: string
117+
database?: string
118+
}): Firestore
119+
export function useFirestore(
120+
optionsOrDatabase: string | { name?: string; database?: string }
121+
): Firestore {
122+
if (typeof optionsOrDatabase === 'string') {
123+
return getFirestore(useFirebaseApp(), optionsOrDatabase)
124+
}
125+
126+
if (optionsOrDatabase.database) {
127+
return getFirestore(
128+
useFirebaseApp(optionsOrDatabase.name),
129+
optionsOrDatabase.database
130+
)
131+
}
132+
133+
return getFirestore(useFirebaseApp(optionsOrDatabase.name))
115134
}

0 commit comments

Comments
 (0)