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

Function getDataAndInit

frontend/src/ts/auth.tsx:118–160  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

116}
117
118async function getDataAndInit(): Promise<boolean> {
119 try {
120 console.log("getting account data");
121 const snapshot = await DB.initSnapshot();
122 //TODO: preload collections for now, remove when __nonReactive is removed from collections
123 await waitForPresetsReady();
124 await waitForTagsReady();
125
126 if (snapshot === false) {
127 throw new Error(
128 "Snapshot didn't initialize due to lacking authentication even though user is authenticated",
129 );
130 }
131
132 void Sentry.setUser(snapshot.uid, snapshot.name);
133
134 await updateConfigFromServer();
135 return true;
136 } catch (error) {
137 console.error(error);
138 if (error instanceof SnapshotInitError) {
139 if (error.responseCode === 429) {
140 showNoticeNotification(
141 "Doing so will save you bandwidth, make the next test be ready faster and will not sign you out (which could mean your new personal best would not save to your account).",
142 {
143 durationMs: 0,
144 },
145 );
146 showNoticeNotification(
147 "You will run into this error if you refresh the website to restart the test. It is NOT recommended to do that. Instead, use tab + enter or just tab (with quick tab mode enabled) to restart the test.",
148 {
149 durationMs: 0,
150 },
151 );
152 }
153
154 showErrorNotification(`Failed to get user data: ${error.message}`);
155 } else {
156 showErrorNotification("Failed to get user data", { error });
157 }
158 return false;
159 }
160}
161
162export async function loadUser(_user: UserType): Promise<void> {
163 if (!(await getDataAndInit())) {

Callers 1

loadUserFunction · 0.85

Calls 4

waitForPresetsReadyFunction · 0.90
waitForTagsReadyFunction · 0.90
showNoticeNotificationFunction · 0.90
showErrorNotificationFunction · 0.90

Tested by

no test coverage detected