Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions frontend/src/ts/firebase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
FirebaseApp,
FirebaseError,
FirebaseOptions,
getApp,
getApps,
initializeApp,
Expand All @@ -21,7 +22,6 @@ import {
indexedDBLocalPersistence,
getAdditionalUserInfo,
} from "firebase/auth";
import { firebaseConfig } from "./constants/firebase-config";
import * as Notifications from "./elements/notifications";
import {
createErrorMessage,
Expand Down Expand Up @@ -52,6 +52,17 @@ const { promise: authPromise, resolve: resolveAuthPromise } =

export async function init(callback: ReadyCallback): Promise<void> {
try {
let firebaseConfig: FirebaseOptions | null;

const constants = import.meta.glob("./constants/*.ts");
const loader = constants["./constants/firebase-config.ts"];
if (loader) {
firebaseConfig = ((await loader()) as { firebaseConfig: FirebaseOptions })
.firebaseConfig;
} else {
throw new Error("No firebase config found.");
}

readyCallback = callback;
app = getApps().length === 0 ? initializeApp(firebaseConfig) : getApp();
Auth = getAuth(app);
Expand All @@ -65,8 +76,6 @@ export async function init(callback: ReadyCallback): Promise<void> {
await callback(true, user);
}
});

resolveAuthPromise();
} catch (e) {
app = undefined;
Auth = undefined;
Expand All @@ -81,6 +90,8 @@ export async function init(callback: ReadyCallback): Promise<void> {
false
);
}
} finally {
resolveAuthPromise();
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"start": "turbo run start",
"start-be": "turbo run start --filter @monkeytype/backend",
"start-fe": "turbo run start --filter @monkeytype/frontend",
"docker": "cd backend && docker compose up",
"docker": "cd backend && npm run docker",
"audit-fe": "cd frontend && npm run audit",
"release": "monkeytype-release",
"release-fe": "monkeytype-release --fe",
Expand Down