From 3fdb220ef988383e6af80b72efb7c7d27e6bccb7 Mon Sep 17 00:00:00 2001 From: Christiaan Scheermeijer Date: Tue, 20 Feb 2024 10:14:46 +0100 Subject: [PATCH] fix: restore personal shelves after registration --- .../src/controllers/AccountController.ts | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/common/src/controllers/AccountController.ts b/packages/common/src/controllers/AccountController.ts index 7a7c64b46..36dae7e8d 100644 --- a/packages/common/src/controllers/AccountController.ts +++ b/packages/common/src/controllers/AccountController.ts @@ -66,8 +66,6 @@ export default class AccountController { if (authData) { await this.getAccount(); - await this.watchHistoryController.restoreWatchHistory(); - await this.favoritesController.restoreFavorites(); } } catch (error: unknown) { logDev('Failed to get user', error); @@ -145,10 +143,9 @@ export default class AccountController { try { const response = await this.accountService.getUser({ config }); + if (response) { await this.afterLogin(response.user, response.customerConsents); - await this.favoritesController.restoreFavorites().catch(logDev); - await this.watchHistoryController.restoreWatchHistory().catch(logDev); } useAccountStore.setState({ loading: false }); @@ -289,7 +286,10 @@ export default class AccountController { const updatedCustomer = await this.accountService.updateCaptureAnswers({ customer, ...capture }); - await this.afterLogin(updatedCustomer, customerConsents, false); + useAccountStore.setState({ + user: updatedCustomer, + customerConsents, + }); return updatedCustomer; }; @@ -499,7 +499,12 @@ export default class AccountController { customerConsents, }); - await Promise.allSettled([shouldReloadSubscription ? this.reloadSubscriptions() : Promise.resolve(), this.getPublisherConsents()]); + await Promise.allSettled([ + shouldReloadSubscription ? this.reloadSubscriptions() : Promise.resolve(), + this.getPublisherConsents(), + this.favoritesController.restoreFavorites(), + this.watchHistoryController.restoreWatchHistory(), + ]); useAccountStore.setState({ loading: false }); } @@ -533,7 +538,7 @@ export default class AccountController { this.profileController.unpersistProfile(); - await this.favoritesController.restoreFavorites().catch(logDev); - await this.watchHistoryController.restoreWatchHistory().catch(logDev); + await this.favoritesController.restoreFavorites(); + await this.watchHistoryController.restoreWatchHistory(); }; }