From 4e1e67fc3de8463e6af79797f7d5986fdfe89e43 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 12 Dec 2022 15:33:55 +0100 Subject: [PATCH] :bug: Fix unexpected redirect on invitation acceptation --- frontend/src/app/main.cljs | 1 + frontend/src/app/main/data/users.cljs | 1 + frontend/src/app/main/ui/routes.cljs | 37 ++++++++------------------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/frontend/src/app/main.cljs b/frontend/src/app/main.cljs index ce313ce90..5831edea8 100644 --- a/frontend/src/app/main.cljs +++ b/frontend/src/app/main.cljs @@ -60,6 +60,7 @@ (rx/merge (rx/of (ev/initialize) (du/initialize-profile)) + (->> stream (rx/filter du/profile-fetched?) (rx/take 1) diff --git a/frontend/src/app/main/data/users.cljs b/frontend/src/app/main/data/users.cljs index 96507a85e..51f962622 100644 --- a/frontend/src/app/main/data/users.cljs +++ b/frontend/src/app/main/data/users.cljs @@ -164,6 +164,7 @@ (swap! storage dissoc :redirect-url) (.replace js/location redirect-url)) (rt/nav' :dashboard-projects {:team-id team-id}))))] + (ptk/reify ::logged-in IDeref (-deref [_] profile) diff --git a/frontend/src/app/main/ui/routes.cljs b/frontend/src/app/main/ui/routes.cljs index 0f0aefd2f..d6ffde3fe 100644 --- a/frontend/src/app/main/ui/routes.cljs +++ b/frontend/src/app/main/ui/routes.cljs @@ -10,9 +10,9 @@ [app.common.uuid :as uuid] [app.config :as cf] [app.main.data.users :as du] + [app.main.repo :as rp] [app.main.store :as st] [app.util.router :as rt] - [app.util.storage :refer [storage]] [beicon.core :as rx] [cljs.spec.alpha :as s] [potok.core :as ptk])) @@ -93,32 +93,17 @@ (defn on-navigate [router path] - (let [match (match-path router path) - profile (:profile @storage) - nopath? (or (= path "") (= path "/")) - path-name (-> match :data :name) - authpath? (some #(= path-name %) '(:auth-login - :auth-register - :auth-register-validate - :auth-register-success - :auth-recovery-request - :auth-recovery)) - authed? (and (not (nil? profile)) - (not= (:id profile) uuid/zero))] + (if-let [match (match-path router path)] + (st/emit! (rt/navigated match)) - (cond - (or (and nopath? authed? (nil? match)) - (and authpath? authed?)) - (st/emit! (rt/nav :dashboard-projects {:team-id (du/get-current-team-id profile)})) - - (and (not authed?) (nil? match)) - (st/emit! (rt/nav :auth-login)) - - (nil? match) - (st/emit! (rt/assign-exception {:type :not-found})) - - :else - (st/emit! (rt/navigated match))))) + ;; We just recheck with an additional profile request; this avoids + ;; some race conditions that causes unexpected redirects on + ;; invitations workflows (and probably other cases). + (->> (rp/query! :profile) + (rx/subs (fn [{:keys [id] :as profile}] + (if (= id uuid/zero) + (st/emit! (rt/nav :auth-login)) + (st/emit! (rt/nav :dashboard-projects {:team-id (du/get-current-team-id profile)})))))))) (defn init-routes []