Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: auto-refresh subscritpion after canceled (#20049)
ecmadao571847d06ee9
diff --git a/frontend/src/components/EmailCodeSigninForm.vue b/frontend/src/components/EmailCodeSigninForm.vueindex 1f66246c71..752e8f4d3c 100644--- a/frontend/src/components/EmailCodeSigninForm.vue+++ b/frontend/src/components/EmailCodeSigninForm.vue@@ -171,6 +171,10 @@ const sendCode = async () => {};const handleSubmit = async () => {+ if (step.value === "email") {+ await sendCode();+ return;+ }const code = state.codeParts.join("");if (!state.email || code.length !== 6) return;emit(diff --git a/frontend/src/react/pages/settings/PurchaseSection.tsx b/frontend/src/react/pages/settings/PurchaseSection.tsxindex a53e22aa94..a0d759d02b 100644--- a/frontend/src/react/pages/settings/PurchaseSection.tsx+++ b/frontend/src/react/pages/settings/PurchaseSection.tsx@@ -117,26 +117,20 @@ export function PurchaseSection({ onRequireEnterprise }: PurchaseSectionProps) {const sessionId = params.get("session_id");if (!sessionId || !allowManage) return;- let cancelled = false;+ const controller = new AbortController();(async () => {try {const status = await subscriptionStore.verifyCheckoutSession(sessionId);- if (status !== "complete" || cancelled) return;+ if (status !== "complete" || controller.signal.aborted) return;- // Poll without updating the store to avoid UI flash.- // On first check, if subscription is already non-FREE (webhook arrived before page load),- // we update the store and skip polling immediately.setPendingPayment(true);- for (let i = 0; i < 30; i++) {- if (cancelled) break;- const sub = await subscriptionStore.fetchSubscription(false);- if (sub && sub.plan !== PlanType.FREE) {- subscriptionStore.setSubscription(sub);- break;- }- await new Promise((r) => setTimeout(r, 2000));+ await subscriptionStore.pollSubscriptionUntil(+ (sub) => sub.plan !== PlanType.FREE,+ { signal: controller.signal }+ );+ if (!controller.signal.aborted) {+ setPendingPayment(false);}- setPendingPayment(false);} catch (e) {console.error("failed to verify checkout session", e);}@@ -145,7 +139,7 @@ export function PurchaseSection({ onRequireEnterprise }: PurchaseSectionProps) {})();return () => {- cancelled = true;+ controller.abort();};}, []);@@ -306,16 +300,11 @@ export function PurchaseSection({ onRequireEnterprise }: PurchaseSectionProps) {if (paymentUrl) {window.location.href = paymentUrl;} else {- // Direct update — poll without updating store to avoid UI flashing.+ // Direct update — wait for the webhook-driven reconciliation.setPendingPayment(true);- for (let i = 0; i < 30; i++) {- const sub = await subscriptionStore.fetchSubscription(false);- if (sub && sub.plan !== PlanType.FREE && sub.seats === seats) {- subscriptionStore.setSubscription(sub);- break;- }- await new Promise((r) => setTimeout(r, 2000));- }+ await subscriptionStore.pollSubscriptionUntil(+ (sub) => sub.plan !== PlanType.FREE && sub.seats === seats+ );setPendingPayment(false);}} catch (e) {@@ -330,6 +319,11 @@ export function PurchaseSection({ onRequireEnterprise }: PurchaseSectionProps) {setCanceling(true);try {await subscriptionStore.cancelPurchase();+ // Wait for the Stripe webhook to reconcile before releasing the UI,+ // so the cached subscription/license reflects the new state.+ await subscriptionStore.pollSubscriptionUntil(+ (sub) => sub.plan === PlanType.FREE+ );pushNotification({module: "bytebase",style: "SUCCESS",diff --git a/frontend/src/store/modules/v1/subscription.ts b/frontend/src/store/modules/v1/subscription.tsindex 5132b56036..a48315cdab 100644--- a/frontend/src/store/modules/v1/subscription.ts+++ b/frontend/src/store/modules/v1/subscription.ts@@ -231,6 +231,34 @@ export const useSubscriptionV1Store = defineStore("subscription_v1", () => {}};+ // Poll GetSubscription until predicate returns true, timeout, or abort.+ // Used after webhook-driven state changes (purchase, update, cancel) to reflect+ // the new subscription in the store without requiring a manual page refresh.+ // On match, the store is updated and the subscription is returned. Returns+ // undefined on timeout or abort without mutating the store.+ const pollSubscriptionUntil = async (+ predicate: (sub: Subscription) => boolean,+ options: {+ timeoutMs?: number;+ intervalMs?: number;+ signal?: AbortSignal;+ } = {}+ ): Promise<Subscription | undefined> => {+ const { timeoutMs = 60_000, intervalMs = 2_000, signal } = options;+ const deadline = Date.now() + timeoutMs;+ while (Date.now() < deadline) {+ if (signal?.aborted) return undefined;+ const sub = await fetchSubscription(false);+ if (signal?.aborted) return undefined;+ if (sub && predicate(sub)) {+ setSubscription(sub);+ return sub;+ }+ await new Promise((r) => setTimeout(r, intervalMs));+ }+ return undefined;+ };+const uploadLicense = async (license: string) => {const request = create(UploadLicenseRequestSchema, {license,@@ -338,6 +366,7 @@ export const useSubscriptionV1Store = defineStore("subscription_v1", () => {instanceMissingLicense,getMinimumRequiredPlan,fetchSubscription,+ pollSubscriptionUntil,uploadLicense,setSubscription,// Purchase actions (SaaS)diff --git a/frontend/src/views/auth/Signin.vue b/frontend/src/views/auth/Signin.vueindex 7909eaeffa..6d1df23770 100644--- a/frontend/src/views/auth/Signin.vue+++ b/frontend/src/views/auth/Signin.vue@@ -280,7 +280,7 @@ const showSignInForm = computed(() => {return (!serverInfo.value?.restriction?.disallowPasswordSignin ||groupedIdentityProviderList.value.length > 0 ||- serverInfo.value.restriction.allowEmailCodeSignin+ serverInfo.value?.restriction?.allowEmailCodeSignin);});