@mxpicture/gcp-functions-frontend 0.1.19 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { GoogleAuthProvider, type Auth } from "firebase/auth";
|
|
2
2
|
import type { FirebaseApp } from "firebase/app";
|
|
3
|
-
import type
|
|
4
|
-
import type { FirebaseConfig } from "../types/firebase.types.js";
|
|
5
|
-
export declare const initializeFirebase: (config: FirebaseConfig) => Promise<{
|
|
3
|
+
import { type Functions } from "firebase/functions";
|
|
4
|
+
import type { FirebaseConfig, FirebaseEmulatorConfig } from "../types/firebase.types.js";
|
|
5
|
+
export declare const initializeFirebase: (config: FirebaseConfig, emu?: FirebaseEmulatorConfig) => Promise<{
|
|
6
6
|
app: FirebaseApp;
|
|
7
7
|
auth: Auth;
|
|
8
8
|
functions: Functions;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { GoogleAuthProvider } from "firebase/auth";
|
|
1
|
+
import { connectAuthEmulator, GoogleAuthProvider, } from "firebase/auth";
|
|
2
|
+
import { connectFunctionsEmulator } from "firebase/functions";
|
|
2
3
|
import { loadFirebaseApp, loadFirebaseAuth, loadFirebaseFunctions, } from "../loader/firebase.loader.js";
|
|
3
4
|
let _inst = null;
|
|
4
5
|
let _config = null;
|
|
5
|
-
|
|
6
|
+
let _emu = null;
|
|
7
|
+
export const initializeFirebase = async (config, emu) => {
|
|
6
8
|
if (_config)
|
|
7
9
|
throw new Error("Firebase config already present");
|
|
8
10
|
_config = { ...config };
|
|
11
|
+
if (emu)
|
|
12
|
+
_emu = { ...emu };
|
|
9
13
|
return configFirebase();
|
|
10
14
|
};
|
|
11
15
|
export const configFirebase = async () => {
|
|
@@ -19,8 +23,12 @@ export const configFirebase = async () => {
|
|
|
19
23
|
const app = initializeApp(_config);
|
|
20
24
|
// Initialize Firebase services
|
|
21
25
|
const auth = getAuth(app);
|
|
22
|
-
|
|
26
|
+
if (_emu?.authHost)
|
|
27
|
+
connectAuthEmulator(auth, `http://${_emu.authHost}:${_emu.authPort ?? 9099}`, { disableWarnings: true });
|
|
23
28
|
const functions = getFunctions(app);
|
|
29
|
+
if (_emu?.functionsHost)
|
|
30
|
+
connectFunctionsEmulator(functions, _emu.functionsHost, _emu.functionsPort ?? 5001);
|
|
31
|
+
const googleProvider = new GoogleAuthProvider();
|
|
24
32
|
_inst = { app, auth, functions, googleProvider };
|
|
25
33
|
}
|
|
26
34
|
return _inst;
|