()
| 116 | } |
| 117 | |
| 118 | async 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 | |
| 162 | export async function loadUser(_user: UserType): Promise<void> { |
| 163 | if (!(await getDataAndInit())) { |
no test coverage detected