Skip to content

Commit 6902b40

Browse files
fehmerMiodec
andauthored
fix: run without firebase-config (@fehmer) (monkeytypegame#7030)
Co-authored-by: Miodec <[email protected]>
1 parent be59c40 commit 6902b40

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

frontend/src/ts/firebase.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
FirebaseApp,
33
FirebaseError,
4+
FirebaseOptions,
45
getApp,
56
getApps,
67
initializeApp,
@@ -21,7 +22,6 @@ import {
2122
indexedDBLocalPersistence,
2223
getAdditionalUserInfo,
2324
} from "firebase/auth";
24-
import { firebaseConfig } from "./constants/firebase-config";
2525
import * as Notifications from "./elements/notifications";
2626
import {
2727
createErrorMessage,
@@ -52,6 +52,17 @@ const { promise: authPromise, resolve: resolveAuthPromise } =
5252

5353
export async function init(callback: ReadyCallback): Promise<void> {
5454
try {
55+
let firebaseConfig: FirebaseOptions | null;
56+
57+
const constants = import.meta.glob("./constants/*.ts");
58+
const loader = constants["./constants/firebase-config.ts"];
59+
if (loader) {
60+
firebaseConfig = ((await loader()) as { firebaseConfig: FirebaseOptions })
61+
.firebaseConfig;
62+
} else {
63+
throw new Error("No firebase config found.");
64+
}
65+
5566
readyCallback = callback;
5667
app = getApps().length === 0 ? initializeApp(firebaseConfig) : getApp();
5768
Auth = getAuth(app);
@@ -65,8 +76,6 @@ export async function init(callback: ReadyCallback): Promise<void> {
6576
await callback(true, user);
6677
}
6778
});
68-
69-
resolveAuthPromise();
7079
} catch (e) {
7180
app = undefined;
7281
Auth = undefined;
@@ -81,6 +90,8 @@ export async function init(callback: ReadyCallback): Promise<void> {
8190
false
8291
);
8392
}
93+
} finally {
94+
resolveAuthPromise();
8495
}
8596
}
8697

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"start": "turbo run start",
3333
"start-be": "turbo run start --filter @monkeytype/backend",
3434
"start-fe": "turbo run start --filter @monkeytype/frontend",
35-
"docker": "cd backend && docker compose up",
35+
"docker": "cd backend && npm run docker",
3636
"audit-fe": "cd frontend && npm run audit",
3737
"release": "monkeytype-release",
3838
"release-fe": "monkeytype-release --fe",

0 commit comments

Comments
 (0)