Created
March 20, 2024 17:48
-
-
Save ArnoldM/ea9a0a91894d95cbba78f19b358ca331 to your computer and use it in GitHub Desktop.
Firebase features injection tokens
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const app = initializeApp(environment.firebase); | |
export const AUTH = new InjectionToken('Firebase auth', { | |
providedIn: 'root', | |
factory: () => { | |
const auth = getAuth(); | |
if (environment.useEmulators) { | |
connectAuthEmulator(auth, 'http://localhost:9099', { | |
disableWarnings: true, | |
}); | |
} | |
return auth; | |
}, | |
}); | |
export const FIRESTORE = new InjectionToken('Firebase firestore', { | |
providedIn: 'root', | |
factory: () => { | |
const firestore = getFirestore(app); | |
if (environment.useEmulators) { | |
connectFirestoreEmulator(firestore, 'localhost', 8080); | |
} | |
return firestore; | |
}, | |
}); | |
export const STORAGE = new InjectionToken('Firebase storage', { | |
providedIn: 'root', | |
factory: () => { | |
const storage = getStorage(); | |
if (environment.useEmulators) { | |
connectStorageEmulator(storage, 'localhost', 9199); | |
} | |
return storage; | |
}, | |
}); | |
export const FUNCTIONS = new InjectionToken('Firebase functions', { | |
providedIn: 'root', | |
factory: () => { | |
const functions = getFunctions(getApp()); | |
if (environment.useEmulators) { | |
connectFunctionsEmulator(functions, 'localhost', 5001); | |
} | |
return functions; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These tokens are defined to be used with rxfire;