From 045358ddbf300996a23bba8d6945b1d7b5f6e862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20S=C3=B3jko?= Date: Mon, 15 Jan 2024 12:42:54 +0100 Subject: [PATCH] fix(auth): add renewal for shared offline subscriptions --- .../Handler/SubscriptionPurchasedEventHandler.ts | 13 +++++++++++++ .../SubscriptionSyncRequestedEventHandler.ts | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/auth/src/Domain/Handler/SubscriptionPurchasedEventHandler.ts b/packages/auth/src/Domain/Handler/SubscriptionPurchasedEventHandler.ts index cde6c4aa3..bcfc560cc 100644 --- a/packages/auth/src/Domain/Handler/SubscriptionPurchasedEventHandler.ts +++ b/packages/auth/src/Domain/Handler/SubscriptionPurchasedEventHandler.ts @@ -34,6 +34,19 @@ export class SubscriptionPurchasedEventHandler implements DomainEventHandlerInte event.payload.timestamp, ) + const renewalResult = await this.renewSharedSubscriptions.execute({ + inviterEmail: event.payload.userEmail, + newSubscriptionId: event.payload.subscriptionId, + newSubscriptionName: event.payload.subscriptionName, + newSubscriptionExpiresAt: event.payload.subscriptionExpiresAt, + timestamp: event.payload.timestamp, + }) + if (renewalResult.isFailed()) { + this.logger.error(`Could not renew shared offline subscriptions: ${renewalResult.getError()}`, { + subscriptionId: event.payload.subscriptionId, + }) + } + await this.roleService.setOfflineUserRole(offlineUserSubscription) return diff --git a/packages/auth/src/Domain/Handler/SubscriptionSyncRequestedEventHandler.ts b/packages/auth/src/Domain/Handler/SubscriptionSyncRequestedEventHandler.ts index 7c7e5e4e4..a8b74463a 100644 --- a/packages/auth/src/Domain/Handler/SubscriptionSyncRequestedEventHandler.ts +++ b/packages/auth/src/Domain/Handler/SubscriptionSyncRequestedEventHandler.ts @@ -51,6 +51,19 @@ export class SubscriptionSyncRequestedEventHandler implements DomainEventHandler event.payload.timestamp, ) + const renewalResult = await this.renewSharedSubscriptions.execute({ + inviterEmail: event.payload.userEmail, + newSubscriptionId: event.payload.subscriptionId, + newSubscriptionName: event.payload.subscriptionName, + newSubscriptionExpiresAt: event.payload.subscriptionExpiresAt, + timestamp: event.payload.timestamp, + }) + if (renewalResult.isFailed()) { + this.logger.error(`Could not renew shared offline subscriptions for user: ${renewalResult.getError()}`, { + subscriptionId: event.payload.subscriptionId, + }) + } + await this.roleService.setOfflineUserRole(offlineUserSubscription) const offlineFeaturesTokenDecoded = this.contentDecoder.decode(