MCPcopy Index your code
hub / github.com/monkeytypegame/monkeytype / init

Function init

frontend/src/ts/firebase.ts:52–92  ·  view source on GitHub ↗
(callback: ReadyCallback)

Source from the content-addressed store, hash-verified

50 promiseWithResolvers();
51
52export async function init(callback: ReadyCallback): Promise<void> {
53 try {
54 let firebaseConfig: FirebaseOptions | null;
55
56 firebaseConfig = (
57 (await import("./constants/firebase-config")) as {
58 firebaseConfig: FirebaseOptions;
59 }
60 ).firebaseConfig;
61
62 readyCallback = callback;
63 app = getApps().length === 0 ? initializeApp(firebaseConfig) : getApp();
64 Auth = getAuth(app);
65
66 const rememberMe =
67 window.localStorage.getItem("firebasePersistence") === "LOCAL";
68 await setPersistence(rememberMe, false);
69
70 onAuthStateChanged(Auth, async (user) => {
71 if (!ignoreAuthCallback) {
72 setUserState(user);
73 await callback(true, user);
74 }
75 });
76 } catch (e) {
77 app = undefined;
78 Auth = undefined;
79 console.error("Firebase failed to initialize", e);
80 await callback(false, null);
81 setUserState(null);
82 if (isDevEnvironment()) {
83 addBanner({
84 level: "notice",
85 text: "Dev Info: Firebase failed to initialize",
86 icon: "fas fa-exclamation-triangle",
87 });
88 }
89 } finally {
90 resolveAuthPromise();
91 }
92}
93
94/**
95 *

Callers 1

index.tsFile · 0.90

Calls 5

onAuthStateChangedFunction · 0.90
isDevEnvironmentFunction · 0.90
addBannerFunction · 0.90
setPersistenceFunction · 0.85
setUserStateFunction · 0.85

Tested by

no test coverage detected