0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-10 09:08:31 -05:00

🐛 Fix unexpected redirect on invitation acceptation

This commit is contained in:
Andrey Antukh 2022-12-12 15:33:55 +01:00
parent c9ad82edc3
commit 44e87e75e6
3 changed files with 13 additions and 26 deletions

View file

@ -60,6 +60,7 @@
(rx/merge (rx/merge
(rx/of (ev/initialize) (rx/of (ev/initialize)
(du/initialize-profile)) (du/initialize-profile))
(->> stream (->> stream
(rx/filter du/profile-fetched?) (rx/filter du/profile-fetched?)
(rx/take 1) (rx/take 1)

View file

@ -164,6 +164,7 @@
(swap! storage dissoc :redirect-url) (swap! storage dissoc :redirect-url)
(.replace js/location redirect-url)) (.replace js/location redirect-url))
(rt/nav' :dashboard-projects {:team-id team-id}))))] (rt/nav' :dashboard-projects {:team-id team-id}))))]
(ptk/reify ::logged-in (ptk/reify ::logged-in
IDeref IDeref
(-deref [_] profile) (-deref [_] profile)

View file

@ -10,9 +10,9 @@
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.config :as cf] [app.config :as cf]
[app.main.data.users :as du] [app.main.data.users :as du]
[app.main.repo :as rp]
[app.main.store :as st] [app.main.store :as st]
[app.util.router :as rt] [app.util.router :as rt]
[app.util.storage :refer [storage]]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[potok.core :as ptk])) [potok.core :as ptk]))
@ -93,32 +93,17 @@
(defn on-navigate (defn on-navigate
[router path] [router path]
(let [match (match-path router path) (if-let [match (match-path router path)]
profile (:profile @storage) (st/emit! (rt/navigated match))
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))]
(cond ;; We just recheck with an additional profile request; this avoids
(or (and nopath? authed? (nil? match)) ;; some race conditions that causes unexpected redirects on
(and authpath? authed?)) ;; invitations workflows (and probably other cases).
(st/emit! (rt/nav :dashboard-projects {:team-id (du/get-current-team-id profile)})) (->> (rp/query! :profile)
(rx/subs (fn [{:keys [id] :as profile}]
(and (not authed?) (nil? match)) (if (= id uuid/zero)
(st/emit! (rt/nav :auth-login)) (st/emit! (rt/nav :auth-login))
(st/emit! (rt/nav :dashboard-projects {:team-id (du/get-current-team-id profile)}))))))))
(nil? match)
(st/emit! (rt/assign-exception {:type :not-found}))
:else
(st/emit! (rt/navigated match)))))
(defn init-routes (defn init-routes
[] []