From 843097a429018f8440ba736673d6a88778004d5c Mon Sep 17 00:00:00 2001 From: Tuna Date: Thu, 13 Nov 2025 19:59:26 +0700 Subject: [PATCH 1/3] fix: trigger access token refresh --- .../src/SubscriptionController.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/subscription-controller/src/SubscriptionController.ts b/packages/subscription-controller/src/SubscriptionController.ts index a3ebf862394..455d5ae7b4c 100644 --- a/packages/subscription-controller/src/SubscriptionController.ts +++ b/packages/subscription-controller/src/SubscriptionController.ts @@ -241,8 +241,6 @@ export class SubscriptionController extends StaticIntervalPollingController()< > { readonly #subscriptionService: ISubscriptionService; - #shouldCallRefreshAuthToken: boolean = false; - /** * Creates a new SubscriptionController instance. * @@ -391,7 +389,8 @@ export class SubscriptionController extends StaticIntervalPollingController()< state.trialedProducts = newTrialedProducts; state.lastSubscription = newLastSubscription; }); - this.#shouldCallRefreshAuthToken = true; + // trigger access token refresh to ensure the user has the latest access token if subscription state change + this.triggerAccessTokenRefresh(); } return newSubscriptions; @@ -466,8 +465,7 @@ export class SubscriptionController extends StaticIntervalPollingController()< const response = await this.#subscriptionService.startSubscriptionWithCard(request); - - this.triggerAccessTokenRefresh(); + // note no need to trigger access token refresh after startSubscriptionWithCard request because this only return stripe checkout session url, subscription not created yet return response; } @@ -730,10 +728,6 @@ export class SubscriptionController extends StaticIntervalPollingController()< async _executePoll(): Promise { await this.getSubscriptions(); - if (this.#shouldCallRefreshAuthToken) { - this.triggerAccessTokenRefresh(); - this.#shouldCallRefreshAuthToken = false; - } } /** From d305b7e69e9d867390ded12038e1c32fa631efd8 Mon Sep 17 00:00:00 2001 From: Tuna Date: Thu, 13 Nov 2025 20:03:52 +0700 Subject: [PATCH 2/3] chore: update changelog --- packages/subscription-controller/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/subscription-controller/CHANGELOG.md b/packages/subscription-controller/CHANGELOG.md index 5e45964d221..f65c4f6da2f 100644 --- a/packages/subscription-controller/CHANGELOG.md +++ b/packages/subscription-controller/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Trigger `triggerAccessTokenRefresh` everytime subscription state change instead of only when polling ([#7149](https://github.com/MetaMask/core/pull/7149)) +- Remove `triggerAccessTokenRefresh` after `startShieldSubscriptionWithCard` ([#7149](https://github.com/MetaMask/core/pull/7149)) + ## [4.2.1] ### Added From 04b3ce9f02c69087d8b556ba2339572873983063 Mon Sep 17 00:00:00 2001 From: Tuna Date: Thu, 13 Nov 2025 20:16:59 +0700 Subject: [PATCH 3/3] fix: remove redundant access token refresh --- .../subscription-controller/src/SubscriptionController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/subscription-controller/src/SubscriptionController.ts b/packages/subscription-controller/src/SubscriptionController.ts index 455d5ae7b4c..6a654d39fed 100644 --- a/packages/subscription-controller/src/SubscriptionController.ts +++ b/packages/subscription-controller/src/SubscriptionController.ts @@ -465,7 +465,7 @@ export class SubscriptionController extends StaticIntervalPollingController()< const response = await this.#subscriptionService.startSubscriptionWithCard(request); - // note no need to trigger access token refresh after startSubscriptionWithCard request because this only return stripe checkout session url, subscription not created yet + // note: no need to trigger access token refresh after startSubscriptionWithCard request because this only return stripe checkout session url, subscription not created yet return response; } @@ -474,7 +474,7 @@ export class SubscriptionController extends StaticIntervalPollingController()< this.#assertIsUserNotSubscribed({ products: request.products }); const response = await this.#subscriptionService.startSubscriptionWithCrypto(request); - this.triggerAccessTokenRefresh(); + return response; }