| 168 | } |
| 169 | |
| 170 | export async function onAuthStateChanged( |
| 171 | authInitialisedAndConnected: boolean, |
| 172 | user: UserType | null, |
| 173 | ): Promise<void> { |
| 174 | console.debug(`account controller ready`); |
| 175 | |
| 176 | let userPromise: Promise<void> = Promise.resolve(); |
| 177 | |
| 178 | if (authInitialisedAndConnected) { |
| 179 | console.debug(`auth state changed, user ${user ? "true" : "false"}`); |
| 180 | if (user) { |
| 181 | setUserId(user.uid); |
| 182 | userPromise = loadUser(user); |
| 183 | } else { |
| 184 | setUserId(null); |
| 185 | DB.setSnapshot(undefined); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | if (!authInitialisedAndConnected || !user) { |
| 190 | void Sentry.clearUser(); |
| 191 | } |
| 192 | |
| 193 | authEvent.dispatch({ |
| 194 | type: "authStateChanged", |
| 195 | data: { isUserSignedIn: user !== null, loadPromise: userPromise }, |
| 196 | }); |
| 197 | } |
| 198 | |
| 199 | export async function signIn( |
| 200 | email: string, |