Skip to content

Instantly share code, notes, and snippets.

@ArnoldM
Created March 20, 2024 17:48
Show Gist options
  • Save ArnoldM/ea9a0a91894d95cbba78f19b358ca331 to your computer and use it in GitHub Desktop.
Save ArnoldM/ea9a0a91894d95cbba78f19b358ca331 to your computer and use it in GitHub Desktop.
Firebase features injection tokens
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;
},
});
@ArnoldM
Copy link
Author

ArnoldM commented Mar 29, 2024

These tokens are defined to be used with rxfire;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment