1- import { initializeApp , type FirebaseApp } from 'firebase/app'
2- import { Firestore , getFirestore } from 'firebase/firestore'
3- import { inject , type App , type InjectionKey } from 'vue'
4- import { getAnalytics , type Analytics } from 'firebase/analytics'
5- import { Database , getDatabase } from 'firebase/database'
1+ import { initializeApp } from 'firebase/app'
62
73export function createFirebaseApp ( ) {
8- const firebaseApp = initializeApp ( {
4+ return initializeApp ( {
95 apiKey : 'AIzaSyAkUKe36TPWL2eZTshgk-Xl4bY_R5SB97U' ,
106 authDomain : 'vue-fire-store.firebaseapp.com' ,
117 databaseURL : 'https://vue-fire-store.firebaseio.com' ,
@@ -15,50 +11,4 @@ export function createFirebaseApp() {
1511 appId : '1:998674887640:web:1e2bb2cc3e5eb2fc3478ad' ,
1612 measurementId : 'G-RL4BTWXKJ7' ,
1713 } )
18-
19- const firestore = getFirestore ( firebaseApp )
20- const database = getDatabase ( firebaseApp )
21- const analytics = getAnalytics ( firebaseApp )
22-
23- // connectFirestoreEmulator(firestore, 'localhost', 8080)
24-
25- return { firebaseApp, firestore, database, analytics }
26- }
27-
28- export function VueFirePlugin ( {
29- firebaseApp,
30- firestore,
31- analytics,
32- database,
33- } : ReturnType < typeof createFirebaseApp > ) {
34- return ( app : App ) => {
35- app . provide ( FirebaseAppInjectKey , firebaseApp )
36- app . provide ( FirestoreInjectKey , firestore )
37- app . provide ( FirebaseAnalyticsInjectKey , analytics )
38- app . provide ( DatabaseInjectKey , database )
39- }
40- }
41-
42- export const FirestoreInjectKey : InjectionKey < Firestore > = Symbol ( 'firestore' )
43- export const DatabaseInjectKey : InjectionKey < Database > = Symbol ( 'database' )
44- export const FirebaseAppInjectKey : InjectionKey < FirebaseApp > =
45- Symbol ( 'firebaseApp' )
46- export const FirebaseAnalyticsInjectKey : InjectionKey < Analytics > =
47- Symbol ( 'analytics' )
48-
49- export function useFirestore ( ) {
50- // TODO: warning with no currentInstance
51- return inject ( FirestoreInjectKey ) !
52- }
53-
54- export function useDatabase ( ) {
55- return inject ( DatabaseInjectKey ) !
56- }
57-
58- export function useFirebaseApp ( ) {
59- return inject ( FirebaseAppInjectKey ) !
60- }
61-
62- export function useFirebaseAnalytics ( ) {
63- return inject ( FirebaseAnalyticsInjectKey ) !
6414}
0 commit comments