From dedeae8641c3e972957306d77193407cc354b9a4 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 24 Nov 2025 11:24:55 +0100 Subject: [PATCH] :bug: Fix incorrect subscription fetching after profile registration --- frontend/src/app/main/data/auth.cljs | 4 +++- frontend/src/app/main/data/profile.cljs | 23 +++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/main/data/auth.cljs b/frontend/src/app/main/data/auth.cljs index cfa11e4263..a933b83590 100644 --- a/frontend/src/app/main/data/auth.cljs +++ b/frontend/src/app/main/data/auth.cljs @@ -195,7 +195,9 @@ (ptk/reify ::login-from-token ptk/WatchEvent (watch [_ _ _] - (->> (rx/of (logged-in (with-meta profile {::ev/source "login-with-token"}))) + (->> (dp/on-fetch-profile-success profile) + (rx/map (fn [profile] + (logged-in (with-meta profile {::ev/source "login-with-token"})))) ;; NOTE: we need this to be asynchronous because the effect ;; should be called before proceed with the login process (rx/observe-on :async))))) diff --git a/frontend/src/app/main/data/profile.cljs b/frontend/src/app/main/data/profile.cljs index 01dd5ba7d3..1a77f6b9d3 100644 --- a/frontend/src/app/main/data/profile.cljs +++ b/frontend/src/app/main/data/profile.cljs @@ -77,22 +77,25 @@ (rx/of (rt/nav-raw :href href))) (rx/throw cause)))) +(defn on-fetch-profile-success + [profile] + (if (and (contains? cf/flags :subscriptions) + (is-authenticated? profile)) + (->> (rp/cmd! :get-subscription-usage {}) + (rx/map (fn [{:keys [editors]}] + (update-in profile [:props :subscription] assoc :editors editors))) + (rx/catch (fn [cause] + (js/console.error "unexpected error on obtaining subscription usage" cause) + (rx/of profile)))) + (rx/of profile))) + (defn fetch-profile [] (ptk/reify ::fetch-profile ptk/WatchEvent (watch [_ _ _] (->> (rp/cmd! :get-profile) - (rx/mapcat (fn [profile] - (if (and (contains? cf/flags :subscriptions) - (is-authenticated? profile)) - (->> (rp/cmd! :get-subscription-usage {}) - (rx/map (fn [{:keys [editors]}] - (update-in profile [:props :subscription] assoc :editors editors))) - (rx/catch (fn [cause] - (js/console.error "unexpected error on obtaining subscription usage" cause) - (rx/of profile)))) - (rx/of profile)))) + (rx/mapcat on-fetch-profile-success) (rx/map (partial ptk/data-event ::profile-fetched)) (rx/catch on-fetch-profile-exception)))))