()
| 336 | } |
| 337 | |
| 338 | async fetchUser(): Promise<User | undefined> { |
| 339 | this.keyManager.clearCache(); |
| 340 | |
| 341 | const oldUser = await this.getUser(); |
| 342 | try { |
| 343 | const token = await this.tokenManager.getAccessToken(); |
| 344 | if (!token) return; |
| 345 | const user = await http.get( |
| 346 | `${constants.API_HOST}${ENDPOINTS.user}`, |
| 347 | token |
| 348 | ); |
| 349 | if (user) { |
| 350 | await this.setUser(user); |
| 351 | if ( |
| 352 | oldUser && |
| 353 | (oldUser.subscription.plan !== user.subscription.plan || |
| 354 | oldUser.subscription.status !== user.subscription.status || |
| 355 | oldUser.subscription.provider !== user.subscription.provider) |
| 356 | ) { |
| 357 | await this.tokenManager._refreshToken(true); |
| 358 | this.db.eventManager.publish( |
| 359 | EVENTS.userSubscriptionUpdated, |
| 360 | user.subscription |
| 361 | ); |
| 362 | } |
| 363 | if (oldUser && !oldUser.isEmailConfirmed && user.isEmailConfirmed) |
| 364 | this.db.eventManager.publish(EVENTS.userEmailConfirmed); |
| 365 | this.db.eventManager.publish(EVENTS.userFetched, user); |
| 366 | return user; |
| 367 | } else { |
| 368 | return oldUser; |
| 369 | } |
| 370 | } catch (e) { |
| 371 | logger.error(e, "Error fetching user"); |
| 372 | return oldUser; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | changePassword(oldPassword: string, newPassword: string) { |
| 377 | return this._updatePassword("change", { |
no test coverage detected